ReflectionMethodAnalyzer::analyze()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 11
nc 4
nop 3
crap 4
1
<?php declare(strict_types = 1);
2
/**
3
 * Created by Ruslan Molodyko.
4
 * Date: 10.09.2016
5
 * Time: 15:33
6
 */
7
namespace samsonframework\container\definition\analyzer\reflection;
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
use samsonframework\container\definition\exception\MethodDefinitionNotFoundException;
14
15
/**
16
 * Class ReflectionMethodAnalyzer
17
 *
18
 * @author Ruslan Molodyko <[email protected]>
19
 */
20
class ReflectionMethodAnalyzer implements MethodAnalyzerInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     * @throws MethodDefinitionAlreadyExistsException
25
     * @throws MethodDefinitionNotFoundException
26
     */
27 4
    public function analyze(
28
        DefinitionAnalyzer $analyzer,
29
        ClassDefinition $classDefinition,
30
        \ReflectionMethod $reflectionMethod
31
    ) {
32 4
        $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...
33
        // Constructor definition is required
34 4
        if ($methodName === '__construct' && !$classDefinition->hasMethod('__construct')) {
35 1
            $classDefinition->defineConstructor()->end();
36
        }
37
        // Set method metadata
38 4
        if ($classDefinition->hasMethod($methodName)) {
39 4
            $classDefinition->getMethod($methodName)
40 4
                ->setModifiers($reflectionMethod->getModifiers())
41 4
                ->setIsPublic($reflectionMethod->isPublic());
42
        }
43 4
    }
44
}
45