ClassLookup::getClassName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Kunstmaan\UtilitiesBundle\Helper;
4
5
use Doctrine\ORM\Proxy\Proxy;
6
7
/**
8
 * Helper for looking up the classname, not the ORM proxy
9
 */
10
class ClassLookup
11
{
12
    /**
13
     * Get full class name of object (ie. class name including full namespace)
14
     *
15
     * @param mixed $object
16
     *
17
     * @return string the name of the class and if the given $object isn't a vaid Object false will be returned
18
     */
19 23
    public static function getClass($object)
20
    {
21 23
        return ($object instanceof Proxy) ? get_parent_class($object) : \get_class($object);
22
    }
23
24
    /**
25
     * Get class name of object (ie. class name without namespace)
26
     *
27
     * @param string|object $reference
28
     *
29
     * @return string
30
     */
31 1
    public static function getClassName($reference)
32
    {
33 1
        $reference = \is_string($reference) ? $reference : self::getClass($reference);
34 1
        $className = explode('\\', $reference);
35
36 1
        return array_pop($className);
37
    }
38
}
39