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

TransientMetadata   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Test Coverage

Coverage 88.46%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 82
ccs 23
cts 26
cp 0.8846
rs 10
c 0
b 0
f 0
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A setDeclaringClass() 0 3 1
A setReflectionProperty() 0 3 1
A getValue() 0 3 1
A __construct() 0 3 1
A getDeclaringClass() 0 3 1
A setValue() 0 3 1
A wakeupReflection() 0 4 1
A isPrimaryKey() 0 3 1
A getValueGenerationExecutor() 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
class TransientMetadata implements Property
13
{
14
    /** @var ClassMetadata */
15
    protected $declaringClass;
16
17
    /** @var ReflectionProperty */
18
    protected $reflection;
19
20
    /** @var string */
21
    protected $name;
22
23 30
    public function __construct(string $name)
24
    {
25 30
        $this->name = $name;
26 30
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 45
    public function getDeclaringClass() : ComponentMetadata
32
    {
33 45
        return $this->declaringClass;
34
    }
35
36 30
    public function setDeclaringClass(ComponentMetadata $declaringClass) : void
37
    {
38 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...
39 30
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 30
    public function getName() : string
45
    {
46 30
        return $this->name;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 30
    public function isPrimaryKey() : bool
53
    {
54 30
        return false;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function setValue($object, $value) : void
61
    {
62
        $this->reflection->setValue($object, $value);
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68 429
    public function getValue($object)
69
    {
70 429
        return $this->reflection->getValue($object);
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76 884
    public function setReflectionProperty(ReflectionProperty $reflectionProperty) : void
77
    {
78 884
        $this->reflection = $reflectionProperty;
79 884
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84 857
    public function wakeupReflection(ReflectionService $reflectionService) : void
85
    {
86 857
        $this->setReflectionProperty(
87 857
            $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\Tra...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

87
            /** @scrutinizer ignore-type */ $reflectionService->getAccessibleProperty($this->declaringClass->getClassName(), $this->name)
Loading history...
88
        );
89 857
    }
90
91 29
    public function getValueGenerationExecutor(AbstractPlatform $platform) : ?ValueGenerationExecutor
92
    {
93 29
        return null;
94
    }
95
}
96