|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of Railt package. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
*/ |
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace Railt\Reflection\Definition\Behaviour; |
|
11
|
|
|
|
|
12
|
|
|
use Railt\Reflection\Contracts\Definition\Behaviour\ProvidesInheritance; |
|
13
|
|
|
use Railt\Reflection\Contracts\Definition\TypeDefinition; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Trait HasInheritance |
|
17
|
|
|
*/ |
|
18
|
|
|
trait HasInheritance |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var string|null |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $extends; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var string[]|array |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $extendedBy = []; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param string|TypeDefinition $type |
|
32
|
|
|
* @return TypeDefinition |
|
33
|
|
|
*/ |
|
34
|
|
|
abstract protected function fetch($type): TypeDefinition; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @return iterable|TypeDefinition[] |
|
38
|
|
|
*/ |
|
39
|
|
|
public function getChildrenInheritance(): iterable |
|
40
|
|
|
{ |
|
41
|
|
|
foreach ($this->extendedBy as $parent) { |
|
42
|
|
|
yield $this->fetch($parent); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return null|TypeDefinition |
|
48
|
|
|
*/ |
|
49
|
8 |
|
public function getParentInheritance(): ?TypeDefinition |
|
50
|
|
|
{ |
|
51
|
8 |
|
return $this->extends ? $this->fetch($this->extends) : null; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param string $name |
|
|
|
|
|
|
56
|
|
|
* @return bool |
|
57
|
|
|
*/ |
|
58
|
|
|
public function hasParent(): bool |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->extends !== null; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param TypeDefinition|string $definition |
|
65
|
|
|
* @return ProvidesInheritance|$this |
|
66
|
|
|
*/ |
|
67
|
89 |
|
public function extends($definition): ProvidesInheritance |
|
68
|
|
|
{ |
|
69
|
89 |
|
$this->extends = $this->nameOf($definition); |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
89 |
|
if ($definition instanceof ProvidesInheritance) { |
|
72
|
89 |
|
$definition->extendsBy($this); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
89 |
|
return $this; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param string|TypeDefinition $definition |
|
80
|
|
|
*/ |
|
81
|
89 |
|
private function extendsBy($definition): void |
|
|
|
|
|
|
82
|
|
|
{ |
|
83
|
89 |
|
$this->extendedBy[] = $this->nameOf($definition); |
|
|
|
|
|
|
84
|
89 |
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param string|TypeDefinition $type |
|
88
|
|
|
* @return bool |
|
89
|
|
|
*/ |
|
90
|
8 |
|
public function isExtends($type): bool |
|
91
|
|
|
{ |
|
92
|
8 |
|
$definition = $this->fetch($type); |
|
93
|
|
|
|
|
94
|
8 |
|
if ($parent = $this->getParentInheritance()) { |
|
95
|
8 |
|
return $parent->instanceOf($definition); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
8 |
|
return false; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.