Completed
Pull Request — master (#1)
by Karsten
03:23
created

PropertyAccessFactoryImpl::create()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 21
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5.0342

Importance

Changes 0
Metric Value
dl 0
loc 21
c 0
b 0
f 0
ccs 8
cts 9
cp 0.8889
rs 8.7624
cc 5
eloc 9
nc 4
nop 2
crap 5.0342
1
<?php
2
/**
3
 * Created by gerk on 13.11.17 08:06
4
 */
5
6
namespace PeekAndPoke\Component\PropertyAccess;
7
8
/**
9
 * @author Karsten J. Gerber <[email protected]>
10
 */
11
class PropertyAccessFactoryImpl implements PropertyAccessFactory
12
{
13
    /**
14
     * @param \ReflectionClass    $class
15
     * @param \ReflectionProperty $property
16
     *
17
     * @return PropertyAccess
18
     */
19 12
    public function create(\ReflectionClass $class, \ReflectionProperty $property)
20
    {
21 12
        if ($property->isStatic()) {
22
            throw new \LogicException('Cannot create property access for static properties');
23
        }
24
25
        // is it a public property
26 12
        if ($property->isPublic()) {
27 2
            return PublicPropertyAccess::create($property->getName());
28
        }
29
30
31
        // can we you the reflection accessor
32 10
        if ($property->isProtected()
33 10
            || $property->getDeclaringClass()->getName() === $class->getName()) {
0 ignored issues
show
introduced by
Consider using $property->class. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
Bug introduced by
Consider using $class->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
34
35 9
            return ReflectionPropertyAccess::create($class, $property->getName());
36
        }
37
38 1
        return ScopedPropertyAccess::create($property->getDeclaringClass()->getName(), $property->getName());
0 ignored issues
show
introduced by
Consider using $property->class. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
39
    }
40
}
41