Passed
Pull Request — 12.3.x (#163)
by Tom
06:34
created

Criteria::setCollection()   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
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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 int $offset,
29
        protected readonly int $limit,
30
        protected readonly mixed $objectValue,
31
        protected readonly array $args,
32
        protected readonly mixed $context,
33
        protected readonly ResolveInfo $info,
34
    ) {
35
    }
36
37
    public function eventName(): string
38
    {
39
        return $this->eventName;
40
    }
41
42
    public function getCriteria(): DoctrineCriteria
43
    {
44
        return $this->criteria;
45
    }
46
47
    /** @return PersistentCollection<array-key, mixed> */
48
    public function getCollection(): Collection
49
    {
50
        return $this->collection;
51
    }
52
53
    /** @param Collection<array-key, mixed> $collection */
54
    public function setCollection(Collection $collection): void
55
    {
56
        $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...
57
    }
58
59
    public function getOffset(): int
60
    {
61
        return $this->offset;
62
    }
63
64
    public function getLimit(): int
65
    {
66
        return $this->limit;
67
    }
68
69
    public function getObjectValue(): mixed
70
    {
71
        return $this->objectValue;
72
    }
73
74
    /** @return mixed[] */
75
    public function getArgs(): array
76
    {
77
        return $this->args;
78
    }
79
80
    public function getContext(): mixed
81
    {
82
        return $this->context;
83
    }
84
85
    public function getInfo(): ResolveInfo
86
    {
87
        return $this->info;
88
    }
89
}
90