Passed
Pull Request — 12.3.x (#158)
by Tom
03:07
created

Criteria::getCollection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApiSkeletons\Doctrine\ORM\GraphQL\Event;
6
7
use Doctrine\Common\Collections\Collection;
8
use Doctrine\Common\Collections\Criteria as DoctrineCriteria;
9
use Doctrine\ORM\PersistentCollection;
10
use GraphQL\Type\Definition\ResolveInfo;
11
use League\Event\HasEventName;
12
13
/**
14
 * This event is dispatched when a Doctrine Criteria is created.
15
 * Define an event using the Association::$criteriaEventName
16
 */
17
class Criteria implements
18
    HasEventName
19
{
20
    /**
21
     * @param PersistentCollection<array-key, mixed> $collection
22
     * @param mixed[]                                $args
23
     */
24
    public function __construct(
25
        protected readonly string $eventName,
26
        protected readonly DoctrineCriteria $criteria,
27
        protected Collection $collection,
28
        protected readonly mixed $objectValue,
29
        protected readonly array $args,
30
        protected readonly mixed $context,
31
        protected readonly ResolveInfo $info,
32
    ) {
33
    }
34
35
    public function eventName(): string
36
    {
37
        return $this->eventName;
38
    }
39
40
    public function getCriteria(): DoctrineCriteria
41
    {
42
        return $this->criteria;
43
    }
44
45
    /** @return PersistentCollection<array-key, mixed> */
46
    public function getCollection(): Collection
47
    {
48
        return $this->collection;
49
    }
50
51
    /** @param Collection<array-key, mixed> $collection */
52
    public function setCollection(Collection $collection): void
53
    {
54
        $this->collection = $collection;
0 ignored issues
show
Documentation Bug introduced by
$collection is of type Doctrine\Common\Collections\Collection, but the property $collection was declared to be of type Doctrine\ORM\PersistentCollection. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
55
    }
56
57
    public function getObjectValue(): mixed
58
    {
59
        return $this->objectValue;
60
    }
61
62
    /** @return mixed[] */
63
    public function getArgs(): array
64
    {
65
        return $this->args;
66
    }
67
68
    public function getContext(): mixed
69
    {
70
        return $this->context;
71
    }
72
73
    public function getInfo(): ResolveInfo
74
    {
75
        return $this->info;
76
    }
77
}
78