TypedNoDefaultReflectionProperty   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 37
ccs 0
cts 15
cp 0
rs 10
c 1
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 3 3
A setValue() 0 15 4
1
<?php
2
3
namespace Doctrine\Common\Reflection;
4
5
use ReflectionProperty;
6
7
/**
8
 * PHP Typed No Default Reflection Property - special override for typed properties without a default value.
9
 */
10
class TypedNoDefaultReflectionProperty extends ReflectionProperty
11
{
12
    /**
13
     * {@inheritDoc}
14
     *
15
     * Checks that a typed property is initialized before accessing its value.
16
     * This is neccessary to avoid PHP error "Error: Typed property must not be accessed before initialization".
17
     * Should be used only for reflecting typed properties without a default value.
18
     */
19
    public function getValue($object = null)
20
    {
21
        return $object !== null && $this->isInitialized($object) ? parent::getValue($object) : null;
0 ignored issues
show
Bug introduced by
The method isInitialized() does not exist on Doctrine\Common\Reflecti...faultReflectionProperty. ( Ignorable by Annotation )

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

21
        return $object !== null && $this->/** @scrutinizer ignore-call */ isInitialized($object) ? parent::getValue($object) : null;

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
22
    }
23
24
    /**
25
     * {@inheritDoc}
26
     *
27
     * Works around the problem with setting typed no default properties to
28
     * NULL which is not supported, instead unset() to uninitialize.
29
     *
30
     * @link https://github.com/doctrine/orm/issues/7999
31
     */
32
    public function setValue($object, $value = null)
33
    {
34
        if ($value === null && $this->hasType() && ! $this->getType()->allowsNull()) {
0 ignored issues
show
Bug introduced by
The method hasType() does not exist on Doctrine\Common\Reflecti...faultReflectionProperty. ( Ignorable by Annotation )

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

34
        if ($value === null && $this->/** @scrutinizer ignore-call */ hasType() && ! $this->getType()->allowsNull()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getType() does not exist on Doctrine\Common\Reflecti...faultReflectionProperty. ( Ignorable by Annotation )

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

34
        if ($value === null && $this->hasType() && ! $this->/** @scrutinizer ignore-call */ getType()->allowsNull()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
            $propertyName = $this->getName();
36
37
            $unsetter = function () use ($propertyName) {
38
                unset($this->$propertyName);
39
            };
40
            $unsetter = $unsetter->bindTo($object, $this->getDeclaringClass()->getName());
41
            $unsetter();
42
43
            return;
44
        }
45
46
        parent::setValue($object, $value);
47
    }
48
}
49