Completed
Push — master ( 7ee214...32fd8d )
by Alberto
19s
created

ProxyGeneratorFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 39
loc 39
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 9 9 3
A key() 4 4 1
A build() 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
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 View Code Duplication
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
    public static function get(MockingStrategyInterface $mockingStrategy): ProxyGenerator
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