Review generated order proxy

from Magic methods
PHP 8.3.33 advanced 6 min 5 issues to find

Review this generated order proxy before it reaches production.

Expose only read-only id and status fields plus a typed cancel action, keep the service and API token out of persistent state, and release resources through an explicit control-flow boundary.

php
<?php
final class OrderProxy
{
    public function __construct(
        private object $service,
        private array $data,
        private string $apiToken,
    ) {}
    public function __get(string $name): mixed
    {
        return $this->data[$name] ?? null;
    }
    public function __set(string $name, mixed $value): void
    {
        $this->data[$name] = $value;
    }
    public function __call(string $name, array $arguments): mixed
    {
        return $this->service->$name(...$arguments);
    }
    public function __serialize(): array {
        return get_object_vars($this);
    }
    public function __destruct() { $this->service->flush(); }
}

generated code is illustrative, not from any one model

Open in playground
Report an error