Completed
Pull Request — master (#2069)
by Andreas
20:35
created

ProxyManagerClassNameResolver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 31
loc 31
ccs 7
cts 9
cp 0.7778
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A getRealClass() 4 4 1
A getClass() 4 4 1
A getClassNameInflector() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ODM\MongoDB\Proxy\Resolver;
6
7
use Doctrine\ODM\MongoDB\Configuration;
8
use ProxyManager\Inflector\ClassNameInflectorInterface;
9
use function get_class;
10
11
/**
12
 * @internal
13
 */
14 View Code Duplication
final class ProxyManagerClassNameResolver implements ClassNameResolver
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
{
16
    /** @var Configuration */
17
    private $configuration;
18
19 1773
    public function __construct(Configuration $configuration)
20
    {
21 1773
        $this->configuration = $configuration;
22 1773
    }
23
24
    /**
25
     * Gets the real class name of a class name that could be a proxy.
26
     */
27 1548
    public function getRealClass(string $class) : string
28
    {
29 1548
        return $this->getClassNameInflector()->getUserClassName($class);
30
    }
31
32
    /**
33
     * Gets the real class name of an object (even if its a proxy).
34
     */
35
    public function getClass(object $object) : string
36
    {
37
        return $this->getRealClass(get_class($object));
38
    }
39
40 1548
    private function getClassNameInflector() : ClassNameInflectorInterface
41
    {
42 1548
        return $this->configuration->getProxyManagerConfiguration()->getClassNameInflector();
43
    }
44
}
45