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

PropertyAccessFactoryImpl   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
dl 0
loc 30
c 0
b 0
f 0
wmc 5
lcom 0
cbo 3
ccs 8
cts 9
cp 0.8889
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B create() 0 21 5
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