Completed
Push — master ( 56c4be...a1e3bd )
by Alexander
7s
created

getConditions()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 19
ccs 11
cts 11
cp 1
rs 8.8571
cc 5
eloc 12
nc 4
nop 2
crap 5
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\ParentClass;
12
13
use ReflectionClass;
14
15
class MethodConditionWithInheritDocFetcher extends AbstractFetcher
16
{
17
    /**
18
     * Fetches conditions from all parent method prototypes recursively
19
     *
20
     * @param ReflectionClass $class
21
     * @param string $methodName
22
     *
23
     * @return array
24
     */
25 19
    public function getConditions(ReflectionClass $class, $methodName)
26
    {
27 19
        $annotations   = [];
28 19
        $parentMethods = [];
29
        while (
30 19
            preg_match('/\@inheritdoc/i', $class->getMethod($methodName)->getDocComment())
31 19
            && ($class = $class->getParentClass())
32 19
            && $class->hasMethod($methodName)
33
        ) {
34 4
            $parentMethods[] = $class->getMethod($methodName);
35
        }
36
37 19
        foreach ($parentMethods as $parentMethod) {
38 4
            $annotations = array_merge($annotations, $this->annotationReader->getMethodAnnotations($parentMethod));
39
        }
40 19
        $contracts = $this->filterContractAnnotation($annotations);
41
42 19
        return $contracts;
43
    }
44
}
45