Failed Conditions
Pull Request — 1.3.x (#71)
by Grégoire
02:49
created

RuntimeReflectionService   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 18
c 1
b 0
f 0
dl 0
loc 70
ccs 23
cts 23
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getClass() 0 3 1
A getParentClasses() 0 7 2
A hasPublicMethod() 0 9 2
A getClassNamespace() 0 5 1
A getClassShortName() 0 5 1
A getAccessibleProperty() 0 11 2
1
<?php
2
3
namespace Doctrine\Persistence\Mapping;
4
5
use Doctrine\Common\Reflection\RuntimePublicReflectionProperty;
6
use ReflectionClass;
7
use ReflectionException;
8
use ReflectionMethod;
9
use ReflectionProperty;
10
use function class_exists;
11
use function class_parents;
12
13
/**
14
 * PHP Runtime Reflection Service.
15
 */
16
class RuntimeReflectionService implements ReflectionService
17
{
18
    /**
19
     * {@inheritDoc}
20
     */
21 2
    public function getParentClasses($class)
22
    {
23 2
        if (! class_exists($class)) {
24 1
            throw MappingException::nonExistingClass($class);
25
        }
26
27 1
        return class_parents($class);
28
    }
29
30
    /**
31
     * {@inheritDoc}
32
     */
33 1
    public function getClassShortName($class)
34
    {
35 1
        $reflectionClass = new ReflectionClass($class);
36
37 1
        return $reflectionClass->getShortName();
38
    }
39
40
    /**
41
     * {@inheritDoc}
42
     */
43 1
    public function getClassNamespace($class)
44
    {
45 1
        $reflectionClass = new ReflectionClass($class);
46
47 1
        return $reflectionClass->getNamespaceName();
48
    }
49
50
    /**
51
     * {@inheritDoc}
52
     */
53 1
    public function getClass($class)
54
    {
55 1
        return new ReflectionClass($class);
56
    }
57
58
    /**
59
     * {@inheritDoc}
60
     */
61 1
    public function getAccessibleProperty($class, $property)
62
    {
63 1
        $reflectionProperty = new ReflectionProperty($class, $property);
64
65 1
        if ($reflectionProperty->isPublic()) {
66 1
            $reflectionProperty = new RuntimePublicReflectionProperty($class, $property);
67
        }
68
69 1
        $reflectionProperty->setAccessible(true);
70
71 1
        return $reflectionProperty;
72
    }
73
74
    /**
75
     * {@inheritDoc}
76
     */
77 1
    public function hasPublicMethod($class, $method)
78
    {
79
        try {
80 1
            $reflectionMethod = new ReflectionMethod($class, $method);
81 1
        } catch (ReflectionException $e) {
82 1
            return false;
83
        }
84
85 1
        return $reflectionMethod->isPublic();
86
    }
87
}
88
89
class_exists(\Doctrine\Common\Persistence\Mapping\RuntimeReflectionService::class);
90