Passed
Pull Request — master (#48)
by Damien
02:20
created

DoctrineHelper::getRealClass()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 4
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace DH\DoctrineAuditBundle;
4
5
use Doctrine\ORM\Proxy\Proxy;
6
7
class DoctrineHelper
8
{
9
    /**
10
     * Gets the real class name of a class name that could be a proxy.
11
     *
12
     * @param object|string $subject
13
     *
14
     * @return string
15
     */
16
    public static function getRealClass($subject): string
17
    {
18
        $class = \is_object($subject) ? \get_class($subject) : $subject;
19
20
        if (false === $pos = strrpos($class, '\\'.Proxy::MARKER.'\\')) {
21
            return $class;
22
        }
23
24
        return substr($class, $pos + Proxy::MARKER_LENGTH + 2);
25
    }
26
}
27