Completed
Push — 2.x ( 63cc53...f14446 )
by Akihito
08:12 queued 06:09
created

AnyMatcher   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 61.9%

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 13
cts 21
cp 0.619
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A setBuildInMethods() 0 7 2
A matchesClass() 0 4 1
A matchesMethod() 0 6 2
A isMagicMethod() 0 4 1
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 22
    public function __construct()
19
    {
20 22
        if (! self::$builtinMethods) {
0 ignored issues
show
Bug Best Practice introduced by
The expression self::$builtinMethods of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
21
            $this->setBuildInMethods();
22
        }
23 22
    }
24
25 1
    private function setBuildInMethods()
26
    {
27
        $methods = (new \ReflectionClass('\ArrayObject'))->getMethods();
28
        foreach ($methods as $method) {
29
            self::$builtinMethods[] = $method->getName();
30
        }
31 1
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 1
    public function matchesClass(\ReflectionClass $class, array $arguments)
37
    {
38 1
        return true;
39 1
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 4
    public function matchesMethod(\ReflectionMethod $method, array $arguments)
45
    {
46 4
        unset($arguments);
47
48
        return ! ($this->isMagicMethod($method->name) || $this->isBuiltinMethod($method->name));
49 4
    }
50
51
    /**
52
     * @param string $name
53
     *
54
     * @return bool
55
     */
56
    private function isMagicMethod($name)
57
    {
58
        return substr($name, 0, 2) === '__';
59
    }
60
61
    /**
62
     * @param string $name
63
     *
64
     * @return bool
65
     */
66 4
    private function isBuiltinMethod($name)
67
    {
68
        $isBuiltin = in_array($name, self::$builtinMethods);
69
70 4
        return $isBuiltin;
71
    }
72
}
73