| Total Complexity | 2 |
| Total Lines | 25 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | |||
| 14 | final readonly class FetchEntity implements FetcherInterface |
||
|
|
|||
| 15 | { |
||
| 16 | private string $entity; |
||
| 17 | |||
| 18 | /** @param class-string $entity */ |
||
| 19 | public function __construct(private ExtendedPdoInterface $pdo, string $entity) |
||
| 20 | { |
||
| 21 | assert(class_exists($entity)); |
||
| 22 | $this->entity = $entity; |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * {@inheritDoc} |
||
| 27 | */ |
||
| 28 | #[Override] |
||
| 29 | public function __invoke(string $sql, array $params): array |
||
| 30 | { |
||
| 31 | $pdoStatement = $this->pdo->perform($sql, $params); |
||
| 32 | |||
| 33 | return $pdoStatement->fetchAll(PDO::FETCH_FUNC, /** @param list<mixed> $args */fn (...$args) => /** @psalm-suppress MixedMethodCall */ |
||
| 34 | new $this->entity(...$args)); |
||
| 35 | } |
||
| 36 | } |
||
| 37 |