AnyMatcher   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 13
c 1
b 0
f 0
dl 0
loc 49
ccs 17
cts 17
cp 1
rs 10

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 5 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