Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
22 | class GraphLookup extends Stage |
||
23 | { |
||
24 | /** @var string */ |
||
25 | private $from; |
||
26 | |||
27 | /** @var string|Expr|array */ |
||
28 | private $startWith; |
||
29 | |||
30 | /** @var string */ |
||
31 | private $connectFromField; |
||
32 | |||
33 | /** @var string */ |
||
34 | private $connectToField; |
||
35 | |||
36 | /** @var string */ |
||
37 | private $as; |
||
38 | |||
39 | /** @var int */ |
||
40 | private $maxDepth; |
||
41 | |||
42 | /** @var string */ |
||
43 | private $depthField; |
||
44 | |||
45 | /** @var Stage\GraphLookup\Match */ |
||
46 | private $restrictSearchWithMatch; |
||
47 | |||
48 | /** @var DocumentManager */ |
||
49 | private $dm; |
||
50 | |||
51 | /** @var ClassMetadata */ |
||
52 | private $class; |
||
53 | |||
54 | /** @var ClassMetadata|null */ |
||
55 | private $targetClass; |
||
56 | |||
57 | /** |
||
58 | * @param string $from Target collection for the $graphLookup operation to |
||
59 | * search, recursively matching the connectFromField to the connectToField. |
||
60 | */ |
||
61 | 11 | public function __construct(Builder $builder, string $from, DocumentManager $documentManager, ClassMetadata $class) |
|
70 | |||
71 | /** |
||
72 | * Name of the array field added to each output document. |
||
73 | * |
||
74 | * Contains the documents traversed in the $graphLookup stage to reach the |
||
75 | * document. |
||
76 | */ |
||
77 | 9 | public function alias(string $alias) : self |
|
83 | |||
84 | /** |
||
85 | * Field name whose value $graphLookup uses to recursively match against the |
||
86 | * connectToField of other documents in the collection. |
||
87 | * |
||
88 | * Optionally, connectFromField may be an array of field names, each of |
||
89 | * which is individually followed through the traversal process. |
||
90 | */ |
||
91 | 10 | public function connectFromField(string $connectFromField) : self |
|
114 | |||
115 | /** |
||
116 | * Field name in other documents against which to match the value of the |
||
117 | * field specified by the connectFromField parameter. |
||
118 | */ |
||
119 | 10 | public function connectToField(string $connectToField) : self |
|
124 | |||
125 | /** |
||
126 | * Name of the field to add to each traversed document in the search path. |
||
127 | * |
||
128 | * The value of this field is the recursion depth for the document, |
||
129 | * represented as a NumberLong. Recursion depth value starts at zero, so the |
||
130 | * first lookup corresponds to zero depth. |
||
131 | */ |
||
132 | 3 | public function depthField(string $depthField) : self |
|
138 | |||
139 | /** |
||
140 | * Target collection for the $graphLookup operation to search, recursively |
||
141 | * matching the connectFromField to the connectToField. |
||
142 | * |
||
143 | * The from collection cannot be sharded and must be in the same database as |
||
144 | * any other collections used in the operation. |
||
145 | */ |
||
146 | 11 | public function from(string $from) : self |
|
172 | |||
173 | /** |
||
174 | * {@inheritdoc} |
||
175 | */ |
||
176 | 9 | public function getExpression() : array |
|
201 | |||
202 | /** |
||
203 | * Non-negative integral number specifying the maximum recursion depth. |
||
204 | */ |
||
205 | 3 | public function maxDepth(int $maxDepth) : self |
|
211 | |||
212 | /** |
||
213 | * A document specifying additional conditions for the recursive search. |
||
214 | */ |
||
215 | 1 | public function restrictSearchWithMatch() : GraphLookup\Match |
|
219 | |||
220 | /** |
||
221 | * Expression that specifies the value of the connectFromField with which to |
||
222 | * start the recursive search. |
||
223 | * |
||
224 | * Optionally, startWith may be array of values, each of which is |
||
225 | * individually followed through the traversal process. |
||
226 | * |
||
227 | * @param string|array|Expr $expression |
||
228 | */ |
||
229 | 10 | public function startWith($expression) : self |
|
235 | |||
236 | /** |
||
237 | * @throws MappingException |
||
238 | */ |
||
239 | 6 | private function fromReference(string $fieldName) : self |
|
272 | |||
273 | 9 | View Code Duplication | private function convertExpression($expression) |
283 | |||
284 | 10 | private function convertTargetFieldName($fieldName) |
|
296 | |||
297 | 10 | private function getDocumentPersister(ClassMetadata $class) : DocumentPersister |
|
301 | |||
302 | 6 | private function getReferencedFieldName(string $fieldName, array $mapping) : string |
|
326 | } |
||
327 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..