Passed
Pull Request — master (#50)
by Damien
02:13
created

DoctrineHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generateProxyClassName() 0 3 1
A getRealClass() 0 9 3
1
<?php
2
3
namespace DH\DoctrineAuditBundle\Helper;
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
    /**
28
     * Given a class name and a proxy namespace returns the proxy name.
29
     *
30
     * @param string $className
31
     * @param string $proxyNamespace
32
     *
33
     * @return string
34
     */
35
    public static function generateProxyClassName($className, $proxyNamespace): string
36
    {
37
        return rtrim($proxyNamespace, '\\').'\\'.Proxy::MARKER.'\\'.ltrim($className, '\\');
38
    }
39
}
40