Completed
Pull Request — master (#2069)
by Andreas
24:59
created

CachingClassNameResolver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ODM\MongoDB\Proxy\Resolver;
6
7
/**
8
 * @internal
9
 */
10
final class CachingClassNameResolver implements ClassNameResolver
11
{
12
    /** @var ClassNameResolver */
13
    private $resolver;
14
15
    /** @var array<string, string> */
16
    private $resolvedNames = [];
17
18
    public function __construct(ClassNameResolver $resolver)
19
    {
20
        $this->resolver = $resolver;
21
    }
22
23
    /**
24
     * Gets the real class name of a class name that could be a proxy.
25
     */
26
    public function getRealClass(string $class) : string
27
    {
28
        if (! isset($this->resolvedNames[$class])) {
29
            $this->resolvedNames[$class] = $this->resolver->getRealClass($class);
30
        }
31
32
        return $this->resolvedNames[$class];
33
    }
34
}
35