AnyMatcher   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
c 0
b 0
f 0
dl 0
loc 52
ccs 19
cts 19
cp 1
rs 10
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A isMagicMethod() 0 3 1
A isBuiltinMethod() 0 3 1
A setBuildInMethods() 0 5 2
A matchesClass() 0 5 1
A matchesMethod() 0 5 2
A __construct() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Aop\Matcher;
6
7
use ArrayObject;
8
use Ray\Aop\AbstractMatcher;
9
use ReflectionClass;
10
use ReflectionMethod;
11
12
use function in_array;
13
use function strpos;
14
15
final class AnyMatcher extends AbstractMatcher
16
{
17
    /** @var string[] */
18
    private static $builtinMethods = [];
19
20 31
    public function __construct()
21
    {
22 31
        parent::__construct();
23 31
24 1
        if (self::$builtinMethods !== []) {
25
            return;
26 31
        }
27
28
        $this->setBuildInMethods();
29
    }
30
31 27
    /**
32
     * {@inheritDoc}
33 27
     */
34
    public function matchesClass(ReflectionClass $class, array $arguments): bool
35
    {
36
        unset($class, $arguments);
37
38
        return true;
39 5
    }
40
41 5
    /**
42
     * {@inheritDoc}
43 5
     */
44
    public function matchesMethod(ReflectionMethod $method, array $arguments): bool
45
    {
46 1
        unset($arguments);
47
48 1
        return ! ($this->isMagicMethod($method->name) || $this->isBuiltinMethod($method->name));
49 1
    }
50 1
51
    private function setBuildInMethods(): void
52 1
    {
53
        $methods = (new ReflectionClass(ArrayObject::class))->getMethods();
54 5
        foreach ($methods as $method) {
55
            self::$builtinMethods[] = $method->name;
56 5
        }
57
    }
58
59
    private function isMagicMethod(string $name): bool
60
    {
61
        return strpos($name, '__') === 0;
62
    }
63
64 5
    private function isBuiltinMethod(string $name): bool
65
    {
66 5
        return in_array($name, self::$builtinMethods, true);
67
    }
68
}
69