Completed
Push — master ( b72f37...0c7d03 )
by Alberto
15s
created

PluginHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 45
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 18 3
A generateFQCN() 0 8 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Moka\Plugin;
5
6
use Moka\Exception\NotImplementedException;
7
8
/**
9
 * Class PluginHelper
10
 * @package Moka\Plugin
11
 */
12
final class PluginHelper
13
{
14
    /**
15
     * Plugin FQCN has to match this template.
16
     */
17
    const PLUGIN_FQCN_TEMPLATE = 'Moka\\Plugin\\%s\\%sPlugin';
18
19
    /**
20
     * @param string $pluginName
21
     * @return string
22
     *
23
     * @throws NotImplementedException
24
     */
25 2
    public static function load(string $pluginName): string
26
    {
27 2
        $pluginFQCN = self::generateFQCN($pluginName);
28
29
        if (
30 2
            !class_exists($pluginFQCN) ||
31 2
            !in_array(PluginInterface::class, class_implements($pluginFQCN), true)
32
        ) {
33 1
            throw new NotImplementedException(
34 1
                sprintf(
35 1
                    'Mocking strategy "%s" does not exist',
36 1
                    $pluginName
37
                )
38
            );
39
        }
40
41 1
        return $pluginFQCN;
42
    }
43
44
    /**
45
     * @param string $pluginName
46
     * @return string
47
     */
48 2
    private static function generateFQCN(string $pluginName): string
49
    {
50 2
        return sprintf(
51 2
            self::PLUGIN_FQCN_TEMPLATE,
52 2
            ucfirst($pluginName),
53 2
            ucfirst($pluginName)
54
        );
55
    }
56
}
57