|
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 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
|
17 |
|
public function getConditions(ReflectionClass $class, $methodName) |
|
26
|
|
|
{ |
|
27
|
17 |
|
$annotations = []; |
|
28
|
17 |
|
$parentMethods = []; |
|
29
|
17 |
|
if (preg_match('/\@inheritdoc/i', $class->getMethod($methodName)->getDocComment())) { |
|
30
|
6 |
|
$this->getParentClassesMethods($class, $methodName, $parentMethods); |
|
31
|
6 |
|
$this->getInterfacesMethods($class, $methodName, $parentMethods); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
17 |
|
foreach ($parentMethods as $parentMethod) { |
|
35
|
6 |
|
$annotations = array_merge($annotations, $this->annotationReader->getMethodAnnotations($parentMethod)); |
|
36
|
|
|
} |
|
37
|
17 |
|
$contracts = $this->filterContractAnnotation($annotations); |
|
38
|
|
|
|
|
39
|
17 |
|
return $contracts; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param ReflectionClass $class |
|
44
|
|
|
* @param string $methodName |
|
45
|
|
|
* @param array $parentMethods |
|
46
|
|
|
*/ |
|
47
|
6 |
|
private function getParentClassesMethods(ReflectionClass $class, $methodName, &$parentMethods) |
|
48
|
|
|
{ |
|
49
|
6 |
|
while (($class = $class->getParentClass()) && $class->hasMethod($methodName)) { |
|
50
|
3 |
|
$parentMethods[] = $class->getMethod($methodName); |
|
51
|
|
|
} |
|
52
|
6 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param ReflectionClass $class |
|
56
|
|
|
* @param string $methodName |
|
57
|
|
|
* @param array $parentMethods |
|
58
|
|
|
*/ |
|
59
|
6 |
|
private function getInterfacesMethods(ReflectionClass $class, $methodName, &$parentMethods) |
|
60
|
|
|
{ |
|
61
|
6 |
|
$interfaces = $class->getInterfaces(); |
|
62
|
6 |
|
foreach ($interfaces as $interface) { |
|
63
|
6 |
|
if ($interface->hasMethod($methodName)) { |
|
64
|
6 |
|
$parentMethods[] = $interface->getMethod($methodName); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
6 |
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|