Code Duplication    Length = 39-49 lines in 2 locations

src/Moka/Factory/ProxyBuilderFactory.php 1 location

@@ 13-61 (lines=49) @@
10
 * Class ProxyBuilderFactory
11
 * @package Moka\Factory
12
 */
13
class ProxyBuilderFactory
14
{
15
    /**
16
     * @var array|ProxyBuilder[]
17
     */
18
    private static $mockBuilders = [];
19
20
    /**
21
     * @param MockingStrategyInterface $mockingStrategy
22
     * @return ProxyBuilder
23
     */
24
    public static function get(MockingStrategyInterface $mockingStrategy): ProxyBuilder
25
    {
26
        $key = self::key($mockingStrategy);
27
        if (!array_key_exists($key, self::$mockBuilders) || !self::$mockBuilders[$key] instanceof ProxyBuilder) {
28
            self::$mockBuilders[$key] = static::build($mockingStrategy);
29
        }
30
31
        return self::$mockBuilders[$key];
32
    }
33
34
    /**
35
     * @param MockingStrategyInterface $mockingStrategy
36
     * @return string
37
     */
38
    private static function key(MockingStrategyInterface $mockingStrategy): string
39
    {
40
        return get_class($mockingStrategy);
41
    }
42
43
    /**
44
     * @param MockingStrategyInterface $mockingStrategy
45
     * @return ProxyBuilder
46
     */
47
    protected static function build(MockingStrategyInterface $mockingStrategy): ProxyBuilder
48
    {
49
        return new ProxyBuilder($mockingStrategy);
50
    }
51
52
    /**
53
     * @return void
54
     */
55
    public static function reset()
56
    {
57
        foreach (self::$mockBuilders as $mockBuilder) {
58
            $mockBuilder->reset();
59
        }
60
    }
61
}
62

src/Moka/Factory/ProxyGeneratorFactory.php 1 location

@@ 13-51 (lines=39) @@
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
    public static function get(MockingStrategyInterface $mockingStrategy): ProxyGenerator
25
    {
26
        $key = self::key($mockingStrategy);
27
        if (!array_key_exists($key, self::$proxyGenerators) || !self::$proxyGenerators[$key] instanceof ProxyGenerator) {
28
            self::$proxyGenerators[$key] = static::build($mockingStrategy);
29
        }
30
31
        return self::$proxyGenerators[$key];
32
    }
33
34
    /**
35
     * @param MockingStrategyInterface $mockingStrategy
36
     * @return string
37
     */
38
    private static function key(MockingStrategyInterface $mockingStrategy): string
39
    {
40
        return get_class($mockingStrategy);
41
    }
42
43
    /**
44
     * @param MockingStrategyInterface $mockingStrategy
45
     * @return ProxyGenerator
46
     */
47
    protected static function build(MockingStrategyInterface $mockingStrategy): ProxyGenerator
48
    {
49
        return new ProxyGenerator($mockingStrategy);
50
    }
51
}
52