Completed
Push — master ( 334094...51b7bf )
by yuuki
01:48
created

AnnotationScanMatcher::has()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
c 0
b 0
f 0
rs 9.2
cc 4
eloc 9
nc 6
nop 2
1
<?php
2
3
/**
4
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
7
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
8
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
10
 * THE SOFTWARE.
11
 *
12
 * This software consists of voluntary contributions made by many individuals
13
 * and is licensed under the MIT license.
14
 *
15
 * Copyright (c) 2015-2016 Yuuki Takezawa
16
 *
17
 */
18
namespace Ytake\LaravelAspect\Matcher;
19
20
use Ray\Aop\AbstractMatcher;
21
use Doctrine\Common\Annotations\AnnotationReader;
22
23
/**
24
 * Class AnnotationScanMatcher
25
 */
26
class AnnotationScanMatcher extends AbstractMatcher
27
{
28
    /** @var AnnotationReader */
29
    private $reader;
30
31
    /**
32
     * ScanMatcher constructor.
33
     */
34
    public function __construct()
35
    {
36
        parent::__construct();
37
        $this->arguments = func_get_args();
38
        $this->reader = new AnnotationReader();
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function matchesClass(\ReflectionClass $class, array $arguments)
45
    {
46
        return $this->has($class, $arguments[0]);
47
    }
48
49
    /**
50
     * @param \ReflectionClass $class
51
     * @param                  $annotation
52
     *
53
     * @return bool
54
     */
55
    private function has(\ReflectionClass $class, $annotation)
56
    {
57
        $count = 0;
58
        foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
59
            $match = $this->reader->getMethodAnnotation($reflectionMethod, $annotation);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $match is correct as $this->reader->getMethod...ionMethod, $annotation) (which targets Doctrine\Common\Annotati...::getMethodAnnotation()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
60
            if ($match) {
61
                $count++;
62
            }
63
        }
64
        if ($count > 1) {
65
            return false;
66
        }
67
68
        return true;
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function matchesMethod(\ReflectionMethod $method, array $arguments)
75
    {
76
        $class = new \ReflectionClass($method->class);
77
78
        return $this->has($class, $arguments[0]);
79
    }
80
}
81