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

RuntimeReflectionService::getClassShortName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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