Files
rank24.pl/.paul/codebase/conventions.md
Jacek Pyziak 0776c4531e Dodano mapę kodu w .paul/codebase/ (7 dokumentów)
Wygenerowano przez równoległą analizę czterech agentów: stack, architektura,
konwencje, integracje, testy, baza danych oraz wykryte problemy i dług techniczny.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 19:57:07 +02:00

78 lines
2.9 KiB
Markdown

# Conventions — rank24.pl
## PHP Naming
| Element | Convention | Example |
|---------|-----------|---------|
| Class files | `class.ClassName.php` | `class.GoogleRank.php` |
| Class names | PascalCase | `GoogleScraper`, `FileCache` |
| Namespaces | lowercase | `controls\`, `factory\`, `view\` |
| Public methods | camelCase | `SaveData()`, `getpagedata()` |
| Private properties | underscore + camelCase | `$_table`, `$_proxy`, `$_header` |
| Local variables | snake_case | `$db_edit_table`, `$last_id` |
| Config keys | snake_case | `$config['db']['host']` |
## File Naming
- Class files: `class.ClassName.php` in `autoload/` subdirectory matching namespace
- Templates: lowercase with hyphens — `main-layout.php`, `site-edit.php`
- Entry points: lowercase — `index.php`, `ajax.php`, `cron.php`
- Directories: lowercase — `autoload/`, `templates/`, `libraries/`
## Code Style
- **Indentation**: 2 spaces
- **Braces**: K&R — opening brace on same line for control structures; new line for methods
- **Spacing**: spaces around `->`, `=`, `=>` operators; spaces inside `( )` for function calls
- **Arrays**: mix of long `array()` in config, short `[]` in Medoo queries
- **Short PHP tags**: templates use `<?` and `<?=` (not `<?php`)
- **No type hints**: no PHP type declarations used anywhere
## Error Handling
- Global error suppression in `index.php`:
```php
error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT ^ E_WARNING ^ E_DEPRECATED);
```
- User alerts via `\S::alert('message')` — stored in session, displayed on next render
- Very limited try/catch; exceptions only in OPD wrapper (`opd.class.php`)
- File/curl errors frequently suppressed with `@` operator
## Database Conventions
- **New code**: use Medoo (`$mdb`), array-based query syntax
- **Legacy code**: use OPD (`$db`), PDO `prepare()` + `execute()`
- Table names: `pro_` prefix (e.g., `pro_rr_clients`, `pro_proxy_servers`)
- All factory methods access DB via `global $mdb;`
## Configuration Access
- All config in `config.php` as `$config['section']['key']` array
- Classes access via `global $config;`
- No `.env` files, no constants for settings (only `OPD_DIR`, `OPD_VERSION`)
## Comments & Docs
- Comments are sparse and in **Polish**
- No docblocks on most classes/methods (exception: `RestClient3.php`)
- Inline comments explain "why" only — rare but present
## Global State
Classes depend on globals declared at bootstrap:
```php
global $db, $mdb, $lang, $sys, $user, $cache, $config, $settings;
```
No dependency injection. No service container.
## Template Conventions
- Savant3 templates receive variables as `$this->varName`
- Tpl templates receive variables as assigned properties, accessed in template scope
- HTML helper components in `templates/html/` — generated via `\Html::form_text()`, `\Html::select()`, etc.
- All UI strings use Polish language
## Language
- All user-facing text, comments, variable names, and commit messages are in **Polish**