Failed Conditions
Pull Request — master (#1)
by Jonathan
13:20 queued 01:26
created

RuntimeReflectionService   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
dl 0
loc 70
rs 10
c 0
b 0
f 0

6 Methods

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