Passed
Push — master ( ec51ae...10f5e3 )
by Adrien
12:18
created

EntityID::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQL\Doctrine\Definition;
6
7
use Doctrine\ORM\EntityManager;
8
use GraphQL\Error\Error;
9
10
/**
11
 * A object used to fetch the entity from DB on demand.
12
 *
13
 * @template T of object
14
 */
15
class EntityID
16
{
17
    /**
18
     * @param class-string<T> $className
19
     */
20 6
    public function __construct(
21
        private readonly EntityManager $entityManager,
22
        /**
23
         * The entity class name.
24
         */
25
        private readonly string $className,
26
        /**
27
         * The entity id.
28
         */
29
        private readonly ?string $id
30
    ) {
31
    }
32
33
    /**
34
     * Get the ID.
35
     */
36 2
    public function getId(): ?string
37
    {
38 2
        return $this->id;
39
    }
40
41
    /**
42
     * Get the entity from DB.
43
     *
44
     * @return T entity
1 ignored issue
show
Bug introduced by
The type GraphQL\Doctrine\Definition\T was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
45
     */
46 4
    public function getEntity(): object
47
    {
48
        /** @var null|T $entity */
49 4
        $entity = $this->entityManager->getRepository($this->className)->find($this->id);
50 4
        if (!$entity) {
51 2
            throw new Error('Entity not found for class `' . $this->className . '` and ID `' . $this->id . '`.');
52
        }
53
54 2
        return $entity;
55
    }
56
}
57