AnyMatcher::isBuiltinMethod()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 1
crap 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
        if (self::$builtinMethods === []) {
24 1
            $this->setBuildInMethods();
25
        }
26 31
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 27
    public function matchesClass(ReflectionClass $class, array $arguments): bool
32
    {
33 27
        unset($class, $arguments);
34
35
        return true;
36
    }
37
38
    /**
39 5
     * {@inheritdoc}
40
     */
41 5
    public function matchesMethod(ReflectionMethod $method, array $arguments): bool
42
    {
43 5
        unset($arguments);
44
45
        return ! ($this->isMagicMethod($method->name) || $this->isBuiltinMethod($method->name));
46 1
    }
47
48 1
    private function setBuildInMethods(): void
49 1
    {
50 1
        $methods = (new ReflectionClass(ArrayObject::class))->getMethods();
51
        foreach ($methods as $method) {
52 1
            self::$builtinMethods[] = $method->name;
53
        }
54 5
    }
55
56 5
    private function isMagicMethod(string $name): bool
57
    {
58
        return strpos($name, '__') === 0;
59
    }
60
61
    private function isBuiltinMethod(string $name): bool
62
    {
63
        return in_array($name, self::$builtinMethods, true);
64 5
    }
65
}
66