ObjectReflector::isInstanceOf()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace Knp\FriendlyContexts\Reflection;
4
5
class ObjectReflector
6
{
7
    public function getReflectionClass($object)
8
    {
9
        return new \ReflectionClass($object);
10
    }
11
12
    public function getClassName($object)
13
    {
14
        return $this->getReflectionClass($object)->getShortName();
15
    }
16
17
    public function getClassNamespace($object)
18
    {
19
        return $this->getReflectionClass($object)->getNamespaceName();
20
    }
21
22
    public function getClassLongName($object)
23
    {
24
        return sprintf(
25
            "%s\\%s",
26
            $this->getClassNamespace($object),
27
            $this->getClassName($object)
28
        );
29
    }
30
31
    public function isInstanceOf($object, $class)
32
    {
33
        return $object instanceof $class || $this->getClassLongName($object) === $class;
34
    }
35
36
    public function getReflectionsFromMetadata($metadata)
37
    {
38
        return array_map(
39
            function ($e) {
40
                return $this->getReflectionClass($e->name);
41
            },
42
            $metadata
43
        );
44
    }
45
}
46