Failed Conditions
Pull Request — master (#7898)
by Guilherme
63:09
created

EmbeddedMetadata::setName()   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 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM\Mapping;
6
7
use Doctrine\DBAL\Platforms\AbstractPlatform;
8
use Doctrine\ORM\Reflection\ReflectionService;
9
use Doctrine\ORM\Sequencing\Executor\EmbeddedValueGeneratorExecutor;
10
use Doctrine\ORM\Sequencing\Executor\ValueGenerationExecutor;
11
use ReflectionProperty;
12
13
class EmbeddedMetadata implements Property
14
{
15
    /** @var ClassMetadata */
16
    private $declaringClass;
17
18
    /** @var ReflectionProperty */
19
    private $reflection;
20
21
    /** @var string */
22
    private $name;
23
24
    /** @var bool */
25
    protected $primaryKey = false;
26
27
    /** @var string */
28
    private $targetEntity;
29
30
    /** @var string */
31
    private $sourceEntity;
32
33
    /** @var string|null */
34
    private $columnPrefix;
35
36
    public function __construct(string $name)
37
    {
38
        $this->name = $name;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getDeclaringClass() : ComponentMetadata
45
    {
46
        return $this->declaringClass;
47
    }
48
49
    public function setDeclaringClass(ComponentMetadata $declaringClass) : void
50
    {
51
        $this->declaringClass = $declaringClass;
0 ignored issues
show
Documentation Bug introduced by
$declaringClass is of type Doctrine\ORM\Mapping\ComponentMetadata, but the property $declaringClass was declared to be of type Doctrine\ORM\Mapping\ClassMetadata. 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...
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function getName() : string
58
    {
59
        return $this->name;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function setName($name) : void
66
    {
67
        $this->name = $name;
68
    }
69
70
    public function setPrimaryKey(bool $isPrimaryKey) : void
71
    {
72
        $this->primaryKey = $isPrimaryKey;
73
    }
74
75
    public function isPrimaryKey() : bool
76
    {
77
        return $this->primaryKey;
78
    }
79
80
    public function getTargetEntity() : string
81
    {
82
        return $this->targetEntity;
83
    }
84
85
    public function setTargetEntity(string $targetEntity) : void
86
    {
87
        $this->targetEntity = $targetEntity;
88
    }
89
90
    public function getSourceEntity() : string
91
    {
92
        return $this->sourceEntity;
93
    }
94
95
    public function setSourceEntity(string $sourceEntity) : void
96
    {
97
        $this->sourceEntity = $sourceEntity;
98
    }
99
100
    public function getColumnPrefix() : ?string
101
    {
102
        return $this->columnPrefix;
103
    }
104
105
    public function setColumnPrefix(string $columnPrefix) : void
106
    {
107
        $this->columnPrefix = $columnPrefix;
108
    }
109
110
    /**
111
     * {@inheritdoc}
112
     */
113
    public function setValue($object, $value) : void
114
    {
115
        $this->reflection->setValue($object, $value);
116
    }
117
118
    /**
119
     * {@inheritdoc}
120
     */
121
    public function getValue($object)
122
    {
123
        return $this->reflection->getValue($object);
124
    }
125
126
    /**
127
     * {@inheritdoc}
128
     */
129
    public function setReflectionProperty(ReflectionProperty $reflectionProperty) : void
130
    {
131
        $this->reflection = $reflectionProperty;
132
    }
133
134
    /**
135
     * {@inheritdoc}
136
     */
137
    public function wakeupReflection(ReflectionService $reflectionService) : void
138
    {
139
        $this->setReflectionProperty(
140
            $reflectionService->getAccessibleProperty($this->declaringClass->getClassName(), $this->name)
0 ignored issues
show
Bug introduced by
It seems like $reflectionService->getA...assName(), $this->name) can also be of type null; however, parameter $reflectionProperty of Doctrine\ORM\Mapping\Emb...setReflectionProperty() does only seem to accept ReflectionProperty, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

140
            /** @scrutinizer ignore-type */ $reflectionService->getAccessibleProperty($this->declaringClass->getClassName(), $this->name)
Loading history...
141
        );
142
    }
143
144
    public function getValueGenerationExecutor(AbstractPlatform $platform) : ?ValueGenerationExecutor
145
    {
146
        return $this->isPrimaryKey()
147
            ? new EmbeddedValueGeneratorExecutor()
148
            : null;
149
    }
150
}
151