|
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 Doctrine\Common\Annotations\Reader; |
|
14
|
|
|
use ReflectionClass; |
|
15
|
|
|
use ReflectionMethod; |
|
16
|
|
|
|
|
17
|
|
|
class MethodConditionWithInheritDocFetcher extends Fetcher |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @param ReflectionClass $class |
|
21
|
|
|
* @param Reader $reader |
|
22
|
|
|
* @param string $methodName |
|
23
|
|
|
* @param array $contracts |
|
24
|
|
|
* @return array |
|
25
|
|
|
*/ |
|
26
|
19 |
|
public function getConditions(ReflectionClass $class, Reader $reader, $methodName, array $contracts = []) |
|
27
|
|
|
{ |
|
28
|
19 |
|
if ($this->hasInheritDoc($class->getMethod($methodName))) { |
|
29
|
4 |
|
return $this->getConditionsWithInheritDoc($class, $reader, $methodName, $contracts); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
15 |
|
return $contracts; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param ReflectionClass $class |
|
37
|
|
|
* @param Reader $reader |
|
38
|
|
|
* @param string $methodName |
|
39
|
|
|
* @param array $contracts |
|
40
|
|
|
* @return array |
|
41
|
|
|
*/ |
|
42
|
4 |
|
private function getConditionsWithInheritDoc(ReflectionClass $class, Reader $reader, $methodName, array $contracts) |
|
43
|
|
|
{ |
|
44
|
4 |
|
$parentClass = $class->getParentClass(); |
|
45
|
4 |
|
if (!$parentClass) { |
|
46
|
|
|
return $contracts; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
4 |
|
$parentMethod = $parentClass->getMethod($methodName); |
|
50
|
4 |
|
$annotations = $reader->getMethodAnnotations($parentMethod); |
|
51
|
4 |
|
$contractAnnotations = $this->getContractAnnotations($annotations); |
|
52
|
4 |
|
$contracts = array_merge($contracts, $contractAnnotations); |
|
53
|
|
|
|
|
54
|
4 |
|
if ($this->hasInheritDoc($parentMethod)) { |
|
55
|
4 |
|
return $this->getConditionsWithInheritDoc($parentClass, $reader, $methodName, $contracts); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
4 |
|
return $contracts; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param ReflectionMethod $method |
|
63
|
|
|
* @return bool |
|
64
|
|
|
*/ |
|
65
|
19 |
|
private function hasInheritDoc(ReflectionMethod $method) |
|
66
|
|
|
{ |
|
67
|
19 |
|
return preg_match('/\@inheritdoc/i', $method->getDocComment()) > 0; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|