PropertyAccessFactoryImpl::create()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 19
c 0
b 0
f 0
rs 9.6111
ccs 9
cts 9
cp 1
cc 5
nc 4
nop 2
crap 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