Files
shopPRO/.serena/memories/code_style_and_conventions.md
Jacek Pyziak 6434933dfb Add configuration for cron key and document code style conventions
- Added cron key to config.php for scheduled tasks.
- Created code_style_and_conventions.md to outline PHP version, file naming, DI pattern, controller wiring, Medoo ORM pitfalls, test conventions, caching, and database structure.
- Added project_overview.md detailing the purpose, tech stack, architecture, entry points, and key classes of the shopPRO project.
- Introduced suggested_commands.md for testing and system utilities commands.
- Added task_completion_checklist.md for a structured approach to completing tasks.
- Included .DS_Store files in autoload and templates directories for macOS compatibility.
2026-02-27 14:57:02 +01:00

1.4 KiB

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)

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