Completed
Push — master ( 2f9c4a...218c91 )
by Alexander
02:43
created

InvariantFetcher   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 49
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getConditions() 0 15 2
A getParentClasses() 0 6 2
A getInterfaces() 0 8 2
1
<?php
2
/**
3
 * PHP Deal framework
4
 *
5
 * @copyright Copyright 2014, Lisachenko Alexander <[email protected]>
6
 *
7
 * This source file is subject to the license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace PhpDeal\Contract\Fetcher\Parent;
12
13
use ReflectionClass;
14
15
class InvariantFetcher extends AbstractFetcher
16
{
17
    /**
18
     * Fetches conditions from all parent classes recursively
19
     *
20
     * @param ReflectionClass $class
21
     *
22
     * @return array
23
     */
24 8
    public function getConditions(ReflectionClass $class)
25
    {
26 8
        $annotations   = [];
27 8
        $parents = [];
28
29 8
        $this->getParentClasses($class, $parents);
30 8
        $this->getInterfaces($class, $parents);
31
32 8
        foreach ($parents as $parent) {
33 6
            $annotations = array_merge($annotations, $this->annotationReader->getClassAnnotations($parent));
34
        }
35 8
        $contracts = $this->filterContractAnnotation($annotations);
36
37 8
        return $contracts;
38
    }
39
40
    /**
41
     * @param ReflectionClass $class
42
     * @param array $parents
43
     */
44 8
    private function getParentClasses(ReflectionClass $class, &$parents)
45
    {
46 8
        while ($class = $class->getParentClass()) {
47 3
            $parents[] = $class;
48
        }
49 8
    }
50
51
    /**
52
     * @param ReflectionClass $class
53
     * @param array $parents
54
     */
55 8
    private function getInterfaces(ReflectionClass $class, &$parents)
56
    {
57 8
        $interfaces = $class->getInterfaces();
58
59 8
        foreach ($interfaces as $interface) {
60 3
            $parents[] = $interface;
61
        }
62 8
    }
63
}
64