Passed
Push — master ( 6137ca...01151b )
by Kevin
02:21
created

ClassMethodMap   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 6
c 1
b 0
f 1
dl 0
loc 24
ccs 7
cts 8
cp 0.875
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsSpecification() 0 3 1
A classInMap() 0 7 2
A methodFor() 0 3 1
1
<?php
2
3
namespace Zenstruck\Porpaginas\Specification\Normalizer;
4
5
/**
6
 * @author Kevin Bond <[email protected]>
7
 */
8
trait ClassMethodMap
9
{
10 26
    protected static function classInMap($specification): bool
11
    {
12 26
        if (!\is_object($specification)) {
13
            return false;
14
        }
15
16 26
        return \array_key_exists(\get_class($specification), static::classMethodMap());
17
    }
18
19 66
    protected static function methodFor(object $specification): string
20
    {
21 66
        return static::classMethodMap()[\get_class($specification)];
22
    }
23
24
    /**
25
     * @return array<string, string>
26
     */
27
    abstract protected static function classMethodMap(): array;
28
29 26
    protected function supportsSpecification($specification): bool
30
    {
31 26
        return self::classInMap($specification);
32
    }
33
}
34