# Code Style and Conventions

## PHP Version
PHP 7.4 — no PHP 8.0+ features allowed.

## File Naming
- New classes: `ClassName.php` (no prefix)
- Legacy classes: `class.ClassName.php` (leave until migrated)

## DI Pattern (all new code)
```php
class ExampleRepository {
    private $db;
    public function __construct($db) {
        $this->db = $db;
    }
    public function find(int $id): ?array {
        return $this->db->get('pp_table', '*', ['id' => $id]);
    }
}
```

## Controller Wiring
- Admin: `admin\App::getControllerFactories()`
- Frontend: `front\App::getControllerFactories()`
- API: `api\ApiRouter::getControllerFactories()`

## Medoo ORM Pitfalls
- `$mdb->delete($table, $where)` takes 2 arguments, NOT 3
- `$mdb->get()` returns `null` when no record, NOT `false`
- After `$mdb->insert()`, check `$mdb->id()` to confirm success

## Test Conventions
- Extend `PHPUnit\Framework\TestCase`
- Mock Medoo: `$this->createMock(\medoo::class)`
- AAA pattern: Arrange, Act, Assert
- Mirror source structure: `tests/Unit/Domain/{Module}/{Class}Test.php`

## Caching
- Redis via `\Shared\Cache\CacheHandler`
- Key pattern: `shop\product:{id}:{lang}:{permutation_hash}`
- Default TTL: 86400 (24h)
- Data serialized — use `unserialize()` after `get()`

## Database
- Table prefix: `pp_`
- Key tables: `pp_shop_products`, `pp_shop_orders`, `pp_shop_categories`, `pp_shop_clients`
