1 | <?php |
||
17 | class ByPropertyHierarchicalLinksFinder { |
||
18 | |||
19 | /** |
||
20 | * @var Store |
||
21 | */ |
||
22 | private $store; |
||
23 | |||
24 | /** |
||
25 | * @var boolean |
||
26 | */ |
||
27 | private $findClosestDescendant = true; |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | private $propertySearchPatternByNamespace = array(); |
||
33 | |||
34 | /** |
||
35 | * @var array |
||
36 | */ |
||
37 | private $antecedentHierarchyLinks = array(); |
||
38 | |||
39 | /** |
||
40 | * @var array |
||
41 | */ |
||
42 | private $closestDescendantLinks = array(); |
||
43 | |||
44 | /** |
||
45 | * @since 1.0 |
||
46 | * |
||
47 | * @param Store $store |
||
48 | */ |
||
49 | 7 | public function __construct( Store $store ) { |
|
52 | |||
53 | /** |
||
54 | * @since 1.0 |
||
55 | * |
||
56 | * @param boolean $findClosestDescendant |
||
57 | */ |
||
58 | 5 | public function setFindClosestDescendantState( $findClosestDescendant ) { |
|
61 | |||
62 | /** |
||
63 | * @since 1.0 |
||
64 | * |
||
65 | * @param array $propertySearchPatternByNamespace |
||
66 | */ |
||
67 | 5 | public function setPropertySearchPatternByNamespace( array $propertySearchPatternByNamespace ) { |
|
70 | |||
71 | /** |
||
72 | * @since 1.0 |
||
73 | * |
||
74 | * @param DIWikiPage $subject |
||
75 | */ |
||
76 | 6 | public function findLinksBySubject( DIWikiPage $subject ) { |
|
77 | |||
78 | 6 | if ( !isset( $this->propertySearchPatternByNamespace[ $subject->getNamespace() ] ) ) { |
|
79 | 1 | return; |
|
80 | } |
||
81 | |||
82 | 5 | $propertySearchPattern = $this->propertySearchPatternByNamespace[ $subject->getNamespace() ]; |
|
83 | |||
84 | 5 | $requestOptions = new RequestOptions(); |
|
85 | 5 | $requestOptions->sort = true; |
|
86 | |||
87 | // Use 3 as buffer to broaden match possibilities |
||
88 | 5 | $requestOptions->limit = 3; |
|
89 | |||
90 | 5 | $this->doResolveAntecedentHierarchyRecursively( |
|
91 | 5 | $subject, |
|
92 | 5 | $propertySearchPattern, |
|
93 | $requestOptions |
||
94 | 5 | ); |
|
95 | |||
96 | 5 | krsort( $this->antecedentHierarchyLinks ); |
|
97 | |||
98 | 5 | if ( !$this->findClosestDescendant ) { |
|
99 | 3 | return; |
|
100 | } |
||
101 | |||
102 | 2 | $this->doFindClosestDescendantByInverseLink( |
|
103 | 2 | $subject, |
|
104 | 2 | $propertySearchPattern, |
|
105 | $requestOptions |
||
106 | 2 | ); |
|
107 | 2 | } |
|
108 | |||
109 | /** |
||
110 | * @since 1.0 |
||
111 | * |
||
112 | * @return array |
||
113 | */ |
||
114 | 6 | public function getParents() { |
|
117 | |||
118 | /** |
||
119 | * @since 1.0 |
||
120 | * |
||
121 | * @return array |
||
122 | */ |
||
123 | 6 | public function getChildren() { |
|
126 | |||
127 | 5 | private function doResolveAntecedentHierarchyRecursively( DIWikiPage $subject, array $propertySearchPattern, RequestOptions $requestOptions, $currentDepth = 0 ) { |
|
172 | |||
173 | 2 | private function doFindClosestDescendantByInverseLink( DIWikiPage $subject, array $propertySearchPattern, RequestOptions $requestOptions ) { |
|
203 | |||
204 | } |
||
205 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.