Failed Conditions
Push — master ( becf73...b9880b )
by Guilherme
09:53
created

EmbeddedClassMetadata   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 97
ccs 0
cts 50
cp 0
rs 10
c 0
b 0
f 0
wmc 12

12 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 3 1
A getValueGenerationExecutor() 0 3 1
A wakeupReflection() 0 4 1
A __construct() 0 5 1
A setName() 0 3 1
A isPrimaryKey() 0 3 1
A setPrimaryKey() 0 3 1
A setValue() 0 3 1
A setReflectionProperty() 0 3 1
A setDeclaringClass() 0 3 1
A getDeclaringClass() 0 3 1
A getName() 0 3 1
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\Planning\ValueGenerationExecutor;
10
use ReflectionProperty;
11
12
/**
13
 * @property MappedSuperClassMetadata $parent
14
 */
15
class EmbeddedClassMetadata extends ComponentMetadata implements Property
16
{
17
    /** @var ClassMetadata */
18
    private $declaringClass;
19
20
    /** @var ReflectionProperty */
21
    private $reflection;
22
23
    /** @var string */
24
    private $name;
25
26
    /** @var bool */
27
    protected $primaryKey = false;
28
29
    public function __construct(string $name, string $className, ?MappedSuperClassMetadata $parent = null)
30
    {
31
        parent::__construct($className, $parent);
0 ignored issues
show
Bug introduced by
$parent of type Doctrine\ORM\Mapping\MappedSuperClassMetadata|null is incompatible with the type Doctrine\ORM\Mapping\ClassMetadataBuildingContext expected by parameter $metadataBuildingContext of Doctrine\ORM\Mapping\Com...Metadata::__construct(). ( Ignorable by Annotation )

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

31
        parent::__construct($className, /** @scrutinizer ignore-type */ $parent);
Loading history...
32
33
        $this->name = $name;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getDeclaringClass() : ComponentMetadata
40
    {
41
        return $this->declaringClass;
42
    }
43
44
    public function setDeclaringClass(ComponentMetadata $declaringClass) : void
45
    {
46
        $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...
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function getName() : string
53
    {
54
        return $this->name;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function setName($name) : void
61
    {
62
        $this->name = $name;
63
    }
64
65
    public function setPrimaryKey(bool $isPrimaryKey) : void
66
    {
67
        $this->primaryKey = $isPrimaryKey;
68
    }
69
70
    public function isPrimaryKey() : bool
71
    {
72
        return $this->primaryKey;
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function setValue($object, $value) : void
79
    {
80
        $this->reflection->setValue($object, $value);
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function getValue($object)
87
    {
88
        return $this->reflection->getValue($object);
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94
    public function setReflectionProperty(ReflectionProperty $reflectionProperty) : void
95
    {
96
        $this->reflection = $reflectionProperty;
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102
    public function wakeupReflection(ReflectionService $reflectionService) : void
103
    {
104
        $this->setReflectionProperty(
105
            $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

105
            /** @scrutinizer ignore-type */ $reflectionService->getAccessibleProperty($this->declaringClass->getClassName(), $this->name)
Loading history...
106
        );
107
    }
108
109
    public function getValueGenerationExecutor(AbstractPlatform $platform) : ?ValueGenerationExecutor
110
    {
111
        return null;
112
    }
113
}
114