ProxyGeneratorFactory::get()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 3

Importance

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