Completed
Push — master ( f4ef0a...d00cab )
by Marco
16s
created

TransientMetadata::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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\ORM\Reflection\ReflectionService;
8
9
class TransientMetadata implements Property
10
{
11
    /** @var ClassMetadata */
12
    protected $declaringClass;
13
14
    /** @var \ReflectionProperty */
15
    protected $reflection;
16
17
    /** @var string */
18
    protected $name;
19
20 30
    public function __construct(string $name)
21
    {
22 30
        $this->name = $name;
23 30
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 45
    public function getDeclaringClass() : ComponentMetadata
29
    {
30 45
        return $this->declaringClass;
31
    }
32
33 30
    public function setDeclaringClass(ComponentMetadata $declaringClass) : void
34
    {
35 30
        $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...
36 30
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 30
    public function getName() : string
42
    {
43 30
        return $this->name;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function isPrimaryKey() : bool
50
    {
51
        return false;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function setValue($object, $value) : void
58
    {
59
        $this->reflection->setValue($object, $value);
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 429
    public function getValue($object)
66
    {
67 429
        return $this->reflection->getValue($object);
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73 880
    public function setReflectionProperty(\ReflectionProperty $reflectionProperty) : void
74
    {
75 880
        $this->reflection = $reflectionProperty;
76 880
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81 853
    public function wakeupReflection(ReflectionService $reflectionService) : void
82
    {
83 853
        $this->setReflectionProperty(
84 853
            $reflectionService->getAccessibleProperty($this->declaringClass->getClassName(), $this->name)
85
        );
86 853
    }
87
}
88