Psalm
Get started
Documentation
Paid support
Plugins
Blog
GitHub
<?php /** * */ class DB { /** * @template T of Entity * * @param class-string<T> $class * * @return T[] */ public function getMany(string $class): array { return []; } } /** * @template T extends object */ class Entity {} /** * @template T of Entity * @template U of RelationshipType */ class RelationshipType { /** @param class-string<T> $model */ public function __construct( public string $localKey, public string $remoteKey, public string $model ) {} } /** * @template T of Entity * * @extends RelationshipType<T, OneToMany> */ #[\Attribute(\Attribute::TARGET_PROPERTY)] class OneToMany extends RelationshipType { /** * @return T[] */ public function resolve(DB $db): array { return $db->getMany($this->model); } }
Snippet created on February 10 2024 at 19:42 UTC
Settings
Get link