Completed
Pull Request — master (#44)
by Alberto
07:10
created

stripName.php ➔ stripName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 2
dl 0
loc 14
ccs 8
cts 8
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Moka\Stub\Helper;
5
6
/**
7
 * @param string $name
8
 * @param array|null $prefixes
9
 * @return string
10
 */
11
function stripName(string $name, array $prefixes = null): string
12
{
13 104
    $prefixes = null !== $prefixes
14 96
        ? array_intersect(array_keys(PREFIXES), $prefixes)
15 104
        : array_keys(PREFIXES);
16
17
    return array_reduce($prefixes, function (string $name, string $prefix) {
18 104
        return preg_replace(
19 104
            sprintf(TEMPLATE_NAME, PREFIXES[$prefix]),
20 104
            '',
21 104
            $name
22
        );
23 104
    }, $name);
24
}
25