Completed
Pull Request — master (#37)
by Angelo
02:21
created

ProxyGeneratorFactory::key()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Moka\Factory;
5
6
use Moka\Generator\ProxyGenerator;
7
use Moka\Strategy\MockingStrategyInterface;
8
9 View Code Duplication
class ProxyGeneratorFactory
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...
10
{
11
    /**
12
     * @var array|ProxyGenerator[]
13
     */
14
    private static $proxyGenerators = [];
15
16
    /**
17
     * @param MockingStrategyInterface $mockingStrategy
18
     * @return ProxyGenerator
19
     */
20
    public static function get(MockingStrategyInterface $mockingStrategy): ProxyGenerator
21
    {
22
        $key = self::key($mockingStrategy);
23
        if (!array_key_exists($key, self::$proxyGenerators) || !self::$proxyGenerators[$key] instanceof ProxyGenerator) {
24
            self::$proxyGenerators[$key] = static::build($mockingStrategy);
25
        }
26
27
        return self::$proxyGenerators[$key];
28
    }
29
30
    /**
31
     * @param MockingStrategyInterface $mockingStrategy
32
     * @return string
33
     */
34
    private static function key(MockingStrategyInterface $mockingStrategy): string
35
    {
36
        return get_class($mockingStrategy);
37
    }
38
39
    /**
40
     * @param MockingStrategyInterface $mockingStrategy
41
     * @return ProxyGenerator
42
     */
43
    protected static function build(MockingStrategyInterface $mockingStrategy): ProxyGenerator
44
    {
45
        return new ProxyGenerator($mockingStrategy);
46
    }
47
}
48