AnnotationMethodAnalyzer::analyze()   B
last analyzed

Complexity

Conditions 5
Paths 7

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 10
cts 10
cp 1
rs 8.6737
c 0
b 0
f 0
cc 5
eloc 12
nc 7
nop 3
crap 5
1
<?php declare(strict_types=1);
0 ignored issues
show
Coding Style introduced by
End of line character is invalid; expected "\n" but found "\r\n"
Loading history...
2
/**
3
 * Created by Ruslan Molodyko.
4
 * Date: 10.09.2016
5
 * Time: 17:48
6
 */
7
namespace samsonframework\container\definition\analyzer\annotation;
8
9
use samsonframework\container\definition\analyzer\DefinitionAnalyzer;
10
use samsonframework\container\definition\analyzer\MethodAnalyzerInterface;
11
use samsonframework\container\definition\ClassDefinition;
12
use samsonframework\container\definition\exception\MethodDefinitionAlreadyExistsException;
13
14
/**
15
 * Class AnnotationMethodAnalyzer
16
 *
17
 * @author Ruslan Molodyko <[email protected]>
18
 */
19
class AnnotationMethodAnalyzer extends AbstractAnnotationAnalyzer implements MethodAnalyzerInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     * @throws MethodDefinitionAlreadyExistsException
24
     */
25 2
    public function analyze(
26
        DefinitionAnalyzer $analyzer,
27
        ClassDefinition $classDefinition,
28
        \ReflectionMethod $reflectionMethod
29
    ) {
30 2
        $methodName = $reflectionMethod->getName();
0 ignored issues
show
Bug introduced by
Consider using $reflectionMethod->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
31
        // Resolve annotations
32 2
        $annotations = $this->reader->getMethodAnnotations($reflectionMethod);
33
        // Create method definition if annotation is exists
34 2
        if (count($annotations)) {
35
            // Define method if not exists
36 2
            if (!$classDefinition->hasMethod($methodName)) {
37 2
                $classDefinition->defineMethod($methodName);
38
            }
39
            // Exec method annotations
40 2
            foreach ($annotations as $annotation) {
41 2
                if ($annotation instanceof ResolveMethodInterface) {
42 2
                    $annotation->resolveMethod($analyzer, $classDefinition, $reflectionMethod);
43
                }
44
            }
45
        }
46 2
    }
47
}
48