Passed
Pull Request — master (#65)
by Saiful
02:02
created

ClassUtils::getClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Xiidea\EasyAuditBundle\Common;
4
5
use Doctrine\Persistence\Proxy;
6
7
class ClassUtils
8
{
9
    /**
10
     * Gets the real class name of a class name that could be a proxy.
11
     *
12
     * @param string $className
13
     *
14
     * @return string
15
     * @psalm-return class-string
16
     */
17
    public static function getRealClass(string $className): string
18
    {
19
        $pos = strrpos($className, '\\' . Proxy::MARKER . '\\');
20
21
        if ($pos === false) {
22
            return $className;
23
        }
24
25
        return substr($className, $pos + Proxy::MARKER_LENGTH + 2);
26
    }
27
28
    /**
29
     * Gets the real class name of an object (even if its a proxy).
30
     *
31
     * @param object $object
32
     *
33
     * @return string
34
     * @psalm-return class-string
35
     */
36
    public static function getClass(object $object): string
37
    {
38
        return self::getRealClass(get_class($object));
39
    }
40
}
41