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 |
||
37 | class Query extends \Doctrine\MongoDB\Query\Query |
||
38 | { |
||
39 | const HINT_REFRESH = 1; |
||
40 | const HINT_SLAVE_OKAY = 2; |
||
41 | const HINT_READ_PREFERENCE = 3; |
||
42 | const HINT_READ_PREFERENCE_TAGS = 4; |
||
43 | const HINT_READ_ONLY = 5; |
||
44 | |||
45 | /** |
||
46 | * The DocumentManager instance. |
||
47 | * |
||
48 | * @var DocumentManager |
||
49 | */ |
||
50 | private $dm; |
||
51 | |||
52 | /** |
||
53 | * The ClassMetadata instance. |
||
54 | * |
||
55 | * @var ClassMetadata |
||
56 | */ |
||
57 | private $class; |
||
58 | |||
59 | /** |
||
60 | * Whether to hydrate results as document class instances. |
||
61 | * |
||
62 | * @var boolean |
||
63 | */ |
||
64 | private $hydrate = true; |
||
65 | |||
66 | /** |
||
67 | * Array of primer Closure instances. |
||
68 | * |
||
69 | * @var array |
||
70 | */ |
||
71 | private $primers = array(); |
||
72 | |||
73 | /** |
||
74 | * Whether or not to require indexes. |
||
75 | * |
||
76 | * @var boolean |
||
77 | */ |
||
78 | private $requireIndexes; |
||
79 | |||
80 | /** |
||
81 | * Hints for UnitOfWork behavior. |
||
82 | * |
||
83 | * @var array |
||
84 | */ |
||
85 | private $unitOfWorkHints = array(); |
||
86 | |||
87 | /** |
||
88 | * Constructor. |
||
89 | * |
||
90 | * @param DocumentManager $dm |
||
91 | * @param ClassMetadata $class |
||
92 | * @param Collection $collection |
||
93 | * @param array $query |
||
94 | * @param array $options |
||
95 | * @param boolean $hydrate |
||
96 | * @param boolean $refresh |
||
97 | * @param array $primers |
||
98 | * @param null $requireIndexes |
||
99 | * @param boolean $readOnly |
||
100 | */ |
||
101 | 190 | public function __construct(DocumentManager $dm, ClassMetadata $class, Collection $collection, array $query = array(), array $options = array(), $hydrate = true, $refresh = false, array $primers = array(), $requireIndexes = null, $readOnly = false) |
|
132 | |||
133 | /** |
||
134 | * Gets the DocumentManager instance. |
||
135 | * |
||
136 | * @return DocumentManager $dm |
||
137 | */ |
||
138 | public function getDocumentManager() |
||
139 | { |
||
140 | return $this->dm; |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * Gets the ClassMetadata instance. |
||
145 | * |
||
146 | * @return ClassMetadata $class |
||
147 | */ |
||
148 | public function getClass() |
||
149 | { |
||
150 | return $this->class; |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * Sets whether or not to hydrate the documents to objects. |
||
155 | * |
||
156 | * @param boolean $hydrate |
||
157 | */ |
||
158 | public function setHydrate($hydrate) |
||
159 | { |
||
160 | $this->hydrate = (boolean) $hydrate; |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * Set whether documents should be registered in UnitOfWork. If document would |
||
165 | * already be managed it will be left intact and new instance returned. |
||
166 | * |
||
167 | * This option has no effect if hydration is disabled. |
||
168 | * |
||
169 | * @param boolean $readOnly |
||
170 | */ |
||
171 | 190 | public function setReadOnly($readOnly) |
|
175 | |||
176 | /** |
||
177 | * Set whether to refresh hydrated documents that are already in the |
||
178 | * identity map. |
||
179 | * |
||
180 | * This option has no effect if hydration is disabled. |
||
181 | * |
||
182 | * @param boolean $refresh |
||
183 | */ |
||
184 | 190 | public function setRefresh($refresh) |
|
188 | |||
189 | /** |
||
190 | * Gets the fields involved in this query. |
||
191 | * |
||
192 | * @return array $fields An array of fields names used in this query. |
||
193 | */ |
||
194 | 22 | public function getFieldsInQuery() |
|
202 | |||
203 | /** |
||
204 | * Check if this query is indexed. |
||
205 | * |
||
206 | * @return bool |
||
207 | */ |
||
208 | 8 | public function isIndexed() |
|
218 | |||
219 | /** |
||
220 | * Gets an array of the unindexed fields in this query. |
||
221 | * |
||
222 | * @return array |
||
223 | */ |
||
224 | 6 | public function getUnindexedFields() |
|
235 | |||
236 | /** |
||
237 | * Execute the query and returns the results. |
||
238 | * |
||
239 | * @throws \Doctrine\ODM\MongoDB\MongoDBException |
||
240 | * @return mixed |
||
241 | */ |
||
242 | 150 | public function execute() |
|
295 | |||
296 | /** |
||
297 | * Prepare the Cursor returned by {@link Query::execute()}. |
||
298 | * |
||
299 | * This method will wrap the base Cursor with an ODM Cursor or EagerCursor, |
||
300 | * and set the hydrate option and UnitOfWork hints. This occurs in addition |
||
301 | * to any preparation done by the base Query class. |
||
302 | * |
||
303 | * @see \Doctrine\MongoDB\Cursor::prepareCursor() |
||
304 | * @param BaseCursor $cursor |
||
305 | * @return CursorInterface |
||
306 | */ |
||
307 | 129 | protected function prepareCursor(BaseCursor $cursor) |
|
325 | |||
326 | /** |
||
327 | * Return whether queries on this document should require indexes. |
||
328 | * |
||
329 | * @return boolean |
||
330 | */ |
||
331 | 150 | private function isIndexRequired() |
|
335 | } |
||
336 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: