loadPlugin.php ➔ loadPlugin()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.1406

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 1
dl 0
loc 27
ccs 9
cts 12
cp 0.75
crap 3.1406
rs 9.488
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Moka\Plugin;
5
6
use Moka\Exception\MissingDependencyException;
7
use Moka\Exception\NotImplementedException;
8
use Moka\Strategy\MockingStrategyInterface;
9
10
/**
11
 * Plugin FQCN has to match this template.
12
 */
13
const PLUGIN_FQCN_TEMPLATE = 'Moka\\Plugin\\%s\\%sPlugin';
14
15
/**
16
 * @param string $pluginName
17
 * @return MockingStrategyInterface
18
 *
19
 * @throws NotImplementedException
20
 * @throws MissingDependencyException
21
 */
22
function loadPlugin(string $pluginName): MockingStrategyInterface
23
{
24
    $generateFQCN = function (string $pluginName): string {
25 1
        return sprintf(
26 1
            PLUGIN_FQCN_TEMPLATE,
27 1
            ucfirst($pluginName),
28 1
            ucfirst($pluginName)
29
        );
30 1
    };
31
32 1
    $pluginFQCN = $generateFQCN($pluginName);
33
34
    if (
35 1
        !class_exists($pluginFQCN) ||
36 1
        !\in_array(PluginInterface::class, class_implements($pluginFQCN), true)
37
    ) {
38
        throw new NotImplementedException(
39
            sprintf(
40
                'Mocking strategy "%s" does not exist',
41
                $pluginName
42
            )
43
        );
44
    }
45
46
    /** @var PluginInterface $pluginFQCN */
47 1
    return $pluginFQCN::getStrategy();
48
}
49