Lines 100.00% 4 / 4
Functions and Methods 100.00% 4 / 4
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
GeneratedHandles 100.00% 4 / 4 100.00% 4 / 4 7 100.00% 1 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 isHandle 100.00% 1 / 1 100.00% 1 / 1 2
 findDomain 100.00% 1 / 1 100.00% 1 / 1 2
 isGeneratedEntityId 100.00% 1 / 1 100.00% 1 / 1 2
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\PHPStan\Manifest;
6
7use PHPStan\Reflection\ReflectionProvider;
8use Stewart\Contracts\Entity\EntityId;
9use Stewart\Contracts\Entity\TypedEntity;
10
11// A handle is recognised through static reflection; its static methods run only once the Manifest shows that the
12// tree is current.
13final readonly class GeneratedHandles
14{
15    public function __construct(private ReflectionProvider $reflection) {}
16
17    public function isHandle(string $class): bool
18    {
19        return $this->reflection->hasClass($class) && $this->reflection->getClass($class)->implementsInterface(TypedEntity::class);
20    }
21
22    public function findDomain(string $class): ?string
23    {
24        return is_a($class, TypedEntity::class, true) ? $class::getDomain() : null;
25    }
26
27    public function isGeneratedEntityId(string $class, string $entityId): bool
28    {
29        return is_a($class, TypedEntity::class, true) && $class::isGeneratedEntityId(new EntityId($entityId));
30    }
31}