Test Failed
Pull Request — master (#856)
by Maxim
06:34
created

isAssociativeArray()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 4
nop 1
dl 0
loc 16
ccs 8
cts 8
cp 1
crap 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Scaffolder;
6
7
if (!\function_exists('trimPostfix')) {
8
    /**
9
     * @internal
10
     */
11
    function trimPostfix(string $name, string $postfix): string
12
    {
13
        $pos = \mb_strripos($name, $postfix);
14
15
        return $pos === false ? $name : \mb_substr($name, 0, $pos);
16
    }
17
}
18
19
if (!\function_exists('defineArrayType')) {
20
    /**
21
     * @internal
22
     */
23
    function defineArrayType(array $array, string $failureType = null): ?string
24
    {
25 7
        $types = \array_map(static fn ($value): string => \gettype($value), $array);
26 7
27 7
        $types = \array_unique($types);
28 2
29
        return \count($types) === 1 ? $types[0] : $failureType;
30
    }
31
}
32