Completed
Pull Request — master (#44)
by Angelo
05:12 queued 02:12
created

plugin.helper.functions.php ➔ generateFQCN()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
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 2
    $pluginFQCN = generateFQCN($pluginName);
25
26
    if (
27 2
        !class_exists($pluginFQCN) ||
28 2
        !\in_array(PluginInterface::class, class_implements($pluginFQCN), true)
29
    ) {
30 1
        throw new NotImplementedException(
31 1
            sprintf(
32 1
                'Mocking strategy "%s" does not exist',
33 1
                $pluginName
34
            )
35
        );
36
    }
37
38
    /** @var PluginInterface $pluginFQCN */
39 1
    return $pluginFQCN::getStrategy();
40
}
41
42
43
/**
44
 * @param string $pluginName
45
 * @return string
46
 */
47
function generateFQCN(string $pluginName): string
48
{
49 2
    return sprintf(
50 2
        PLUGIN_FQCN_TEMPLATE,
51 2
        ucfirst($pluginName),
52 2
        ucfirst($pluginName)
53
    );
54
}
55