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

MethodConditionWithInheritDocFetcher::getConditionsWithInheritDoc()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3.0067

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
ccs 10
cts 11
cp 0.9091
rs 9.4285
cc 3
eloc 11
nc 3
nop 4
crap 3.0067
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