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 |
||
21 | class GraphLookup extends Stage |
||
22 | { |
||
23 | /** @var string */ |
||
24 | private $from; |
||
25 | |||
26 | /** @var string|Expr|array */ |
||
27 | private $startWith; |
||
28 | |||
29 | /** @var string */ |
||
30 | private $connectFromField; |
||
31 | |||
32 | /** @var string */ |
||
33 | private $connectToField; |
||
34 | |||
35 | /** @var string */ |
||
36 | private $as; |
||
37 | |||
38 | /** @var int */ |
||
39 | private $maxDepth; |
||
40 | |||
41 | /** @var string */ |
||
42 | private $depthField; |
||
43 | |||
44 | /** @var Stage\GraphLookup\Match */ |
||
45 | private $restrictSearchWithMatch; |
||
46 | |||
47 | /** @var DocumentManager */ |
||
48 | private $dm; |
||
49 | |||
50 | /** @var ClassMetadata */ |
||
51 | private $class; |
||
52 | |||
53 | /** @var ClassMetadata */ |
||
54 | private $targetClass; |
||
55 | |||
56 | /** |
||
57 | * @param string $from Target collection for the $graphLookup operation to |
||
58 | * search, recursively matching the connectFromField to the connectToField. |
||
59 | */ |
||
60 | 11 | public function __construct(Builder $builder, string $from, DocumentManager $documentManager, ClassMetadata $class) |
|
69 | |||
70 | /** |
||
71 | * Name of the array field added to each output document. |
||
72 | * |
||
73 | * Contains the documents traversed in the $graphLookup stage to reach the |
||
74 | * document. |
||
75 | */ |
||
76 | 9 | public function alias(string $alias) : self |
|
82 | |||
83 | /** |
||
84 | * Field name whose value $graphLookup uses to recursively match against the |
||
85 | * connectToField of other documents in the collection. |
||
86 | * |
||
87 | * Optionally, connectFromField may be an array of field names, each of |
||
88 | * which is individually followed through the traversal process. |
||
89 | */ |
||
90 | 10 | public function connectFromField(string $connectFromField) : self |
|
113 | |||
114 | /** |
||
115 | * Field name in other documents against which to match the value of the |
||
116 | * field specified by the connectFromField parameter. |
||
117 | */ |
||
118 | 10 | public function connectToField(string $connectToField) : self |
|
123 | |||
124 | /** |
||
125 | * Name of the field to add to each traversed document in the search path. |
||
126 | * |
||
127 | * The value of this field is the recursion depth for the document, |
||
128 | * represented as a NumberLong. Recursion depth value starts at zero, so the |
||
129 | * first lookup corresponds to zero depth. |
||
130 | */ |
||
131 | 3 | public function depthField(string $depthField) : self |
|
137 | |||
138 | /** |
||
139 | * Target collection for the $graphLookup operation to search, recursively |
||
140 | * matching the connectFromField to the connectToField. |
||
141 | * |
||
142 | * The from collection cannot be sharded and must be in the same database as |
||
143 | * any other collections used in the operation. |
||
144 | */ |
||
145 | 11 | public function from(string $from) : self |
|
171 | |||
172 | /** |
||
173 | * {@inheritdoc} |
||
174 | */ |
||
175 | 9 | public function getExpression() : array |
|
200 | |||
201 | /** |
||
202 | * Non-negative integral number specifying the maximum recursion depth. |
||
203 | */ |
||
204 | 3 | public function maxDepth(int $maxDepth) : self |
|
210 | |||
211 | /** |
||
212 | * A document specifying additional conditions for the recursive search. |
||
213 | */ |
||
214 | 1 | public function restrictSearchWithMatch() : GraphLookup\Match |
|
218 | |||
219 | /** |
||
220 | * Expression that specifies the value of the connectFromField with which to |
||
221 | * start the recursive search. |
||
222 | * |
||
223 | * Optionally, startWith may be array of values, each of which is |
||
224 | * individually followed through the traversal process. |
||
225 | * |
||
226 | * @param string|array|Expr $expression |
||
227 | */ |
||
228 | 10 | public function startWith($expression) : self |
|
234 | |||
235 | /** |
||
236 | * @throws MappingException |
||
237 | */ |
||
238 | 6 | private function fromReference(string $fieldName) : self |
|
271 | |||
272 | 9 | View Code Duplication | private function convertExpression($expression) |
273 | { |
||
274 | 9 | if (is_array($expression)) { |
|
275 | return array_map([$this, 'convertExpression'], $expression); |
||
276 | 9 | } elseif (is_string($expression) && substr($expression, 0, 1) === '$') { |
|
277 | 9 | return '$' . $this->getDocumentPersister($this->class)->prepareFieldName(substr($expression, 1)); |
|
278 | } |
||
279 | |||
280 | return Type::convertPHPToDatabaseValue(Expr::convertExpression($expression)); |
||
281 | } |
||
282 | |||
283 | 10 | private function convertTargetFieldName($fieldName) |
|
295 | |||
296 | 10 | private function getDocumentPersister(ClassMetadata $class) : DocumentPersister |
|
300 | |||
301 | 6 | private function getReferencedFieldName(string $fieldName, array $mapping) : string |
|
321 | } |
||
322 |
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.