Completed
Branch 2.x (867c01)
by Akihito
09:30
created

AnyMatcher   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 9
c 3
b 1
f 1
lcom 1
cbo 1
dl 0
loc 62
ccs 21
cts 21
cp 1
rs 10

6 Methods

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