PropertyAccessFactoryImpl   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 9
dl 0
loc 27
c 0
b 0
f 0
rs 10
ccs 9
cts 9
cp 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 19 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 50
    public function create(\ReflectionClass $class, \ReflectionProperty $property)
20
    {
21 50
        if ($property->isStatic()) {
22 1
            throw new \LogicException('Cannot create property access for static properties');
23
        }
24
25
        // is it a public property
26 49
        if ($property->isPublic()) {
27 19
            return PublicPropertyAccess::create($property->name);
28
        }
29
30
        // can we you the reflection accessor
31 47
        if ($property->isProtected() ||
32 47
            $property->getDeclaringClass()->name === $class->name) {
33
34 46
            return ReflectionPropertyAccess::create($class, $property->name);
35
        }
36
37 38
        return ScopedPropertyAccess::create($property->getDeclaringClass()->name, $property->name);
38
    }
39
}
40