Failed Conditions
Push — master ( a3e53b...559253 )
by Guilherme
14:58
created

EmbeddedMetadata::setName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
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\ValueGenerationExecutor;
10
use ReflectionProperty;
11
12
class EmbeddedMetadata implements Property
13
{
14
    /** @var ClassMetadata */
15
    private $declaringClass;
16
17
    /** @var ReflectionProperty */
18
    private $reflection;
19
20
    /** @var string */
21
    private $name;
22
23
    /** @var bool */
24
    protected $primaryKey = false;
25
26
    /** @var string */
27
    private $targetEntity;
28
29
    /** @var string */
30
    private $sourceEntity;
31
32
    /** @var string|null */
33
    private $columnPrefix;
34
35
    public function __construct(string $name)
36
    {
37
        $this->name = $name;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function getDeclaringClass() : ComponentMetadata
44
    {
45
        return $this->declaringClass;
46
    }
47
48
    public function setDeclaringClass(ComponentMetadata $declaringClass) : void
49
    {
50
        $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...
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function getName() : string
57
    {
58
        return $this->name;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function setName($name) : void
65
    {
66
        $this->name = $name;
67
    }
68
69
    public function setPrimaryKey(bool $isPrimaryKey) : void
70
    {
71
        $this->primaryKey = $isPrimaryKey;
72
    }
73
74
    public function isPrimaryKey() : bool
75
    {
76
        return $this->primaryKey;
77
    }
78
79
    public function getTargetEntity() : string
80
    {
81
        return $this->targetEntity;
82
    }
83
84
    public function setTargetEntity(string $targetEntity) : void
85
    {
86
        $this->targetEntity = $targetEntity;
87
    }
88
89
    public function getSourceEntity() : string
90
    {
91
        return $this->sourceEntity;
92
    }
93
94
    public function setSourceEntity(string $sourceEntity) : void
95
    {
96
        $this->sourceEntity = $sourceEntity;
97
    }
98
99
    public function getColumnPrefix() : ?string
100
    {
101
        return $this->columnPrefix;
102
    }
103
104
    public function setColumnPrefix(string $columnPrefix) : void
105
    {
106
        $this->columnPrefix = $columnPrefix;
107
    }
108
109
    /**
110
     * {@inheritdoc}
111
     */
112
    public function setValue($object, $value) : void
113
    {
114
        $this->reflection->setValue($object, $value);
115
    }
116
117
    /**
118
     * {@inheritdoc}
119
     */
120
    public function getValue($object)
121
    {
122
        return $this->reflection->getValue($object);
123
    }
124
125
    /**
126
     * {@inheritdoc}
127
     */
128
    public function setReflectionProperty(ReflectionProperty $reflectionProperty) : void
129
    {
130
        $this->reflection = $reflectionProperty;
131
    }
132
133
    /**
134
     * {@inheritdoc}
135
     */
136
    public function wakeupReflection(ReflectionService $reflectionService) : void
137
    {
138
        $this->setReflectionProperty(
139
            $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

139
            /** @scrutinizer ignore-type */ $reflectionService->getAccessibleProperty($this->declaringClass->getClassName(), $this->name)
Loading history...
140
        );
141
    }
142
143
    public function getValueGenerationExecutor(AbstractPlatform $platform) : ?ValueGenerationExecutor
144
    {
145
        return $this->isPrimaryKey()
146
            ? new EmbeddedValueGeneratorExecutor()
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\Mapping\Emb...dValueGeneratorExecutor 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...
147
            : null;
148
    }
149
}
150