Completed
Push — 2.x ( c097b6...d6b11c )
by Akihito
04:58 queued 03:00
created

AnnotatedClass   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 58.33%

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 7
c 4
b 1
f 1
lcom 2
cbo 5
dl 0
loc 63
ccs 14
cts 24
cp 0.5833
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getNewInstance() 0 15 3
A getPostConstruct() 0 13 3
1
<?php
2
/**
3
 * This file is part of the Ray.Di package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace Ray\Di;
8
9
use Doctrine\Common\Annotations\AnnotationReader;
10
use Doctrine\Common\Annotations\AnnotationRegistry;
11
12
final class AnnotatedClass
13
{
14
    /**
15
     * @var AnnotationReader
16
     */
17
    private $reader;
18
19
    /**
20
     * @var AnnotatedClassMethods
21
     */
22
    private $injectionMethod;
23
24 23
    public function __construct(AnnotationReader $reader)
25
    {
26
        AnnotationRegistry::registerFile(__DIR__ . '/DoctrineAnnotations.php');
27 23
        $this->reader = $reader;
28
        $this->injectionMethod = new AnnotatedClassMethods($reader);
29
    }
30
31
    /**
32
     * Return factory instance
33
     *
34
     * @param \ReflectionClass $class Target class reflection
35
     *
36
     * @return NewInstance
37
     */
38 23
    public function getNewInstance(\ReflectionClass $class)
39
    {
40
        $setterMethods = new SetterMethods([]);
41
        $methods = $class->getMethods();
42
        foreach ($methods as $method) {
43 10
            if ($method->name === '__construct') {
44 9
                continue;
45
            }
46
            $setterMethods->add($this->injectionMethod->getSetterMethod($method));
47 12
        }
48
        $name = $this->injectionMethod->getConstructorName($class);
49
        $newInstance = new NewInstance($class, $setterMethods, $name);
50
51 23
        return $newInstance;
52 23
    }
53
54
    /**
55
     * Return @-PostConstruct method reflection
56
     *
57
     * @param \ReflectionClass $class
58
     *
59
     * @return null|\ReflectionMethod
60
     */
61 23
    public function getPostConstruct(\ReflectionClass $class)
62
    {
63
        $methods = $class->getMethods();
64
        foreach ($methods as $method) {
65
            /* @var $annotation \Ray\Di\Di\PostConstruct|null */
66
            $annotation = $this->reader->getMethodAnnotation($method, 'Ray\Di\Di\PostConstruct');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $annotation is correct as $this->reader->getMethod...Di\\Di\\PostConstruct') (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...
67 9
            if ($annotation) {
68 5
                return $method;
69
            }
70 12
        }
71
72 23
        return null;
73 23
    }
74
}
75