Completed
Push — master ( a2c36c...334094 )
by yuuki
01:58
created

AnnotationScanMatcher::matchesClass()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 16
Code Lines 10

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
dl 16
loc 16
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
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 View Code Duplication
    public function matchesClass(\ReflectionClass $class, array $arguments)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
    {
46
        $count = 0;
47
        $annotation = $arguments[0];
48
        foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
49
            $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...
50
            if ($match) {
51
                $count++;
52
            }
53
        }
54
        if ($count > 1) {
55
            return false;
56
        }
57
58
        return true;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 View Code Duplication
    public function matchesMethod(\ReflectionMethod $method, array $arguments)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
    {
66
        $count = 0;
67
        $annotation = $arguments[0];
68
        $reflectionClass = new \ReflectionClass($method->class);
69
        foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
70
            $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...
71
            if ($match) {
72
                $count++;
73
            }
74
        }
75
        if ($count > 1) {
76
            return false;
77
        }
78
79
        return true;
80
    }
81
}
82