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 | /** @deprecated */ |
||
41 | const HINT_SLAVE_OKAY = 2; |
||
42 | const HINT_READ_PREFERENCE = 3; |
||
43 | const HINT_READ_PREFERENCE_TAGS = 4; |
||
44 | const HINT_READ_ONLY = 5; |
||
45 | |||
46 | /** |
||
47 | * The DocumentManager instance. |
||
48 | * |
||
49 | * @var DocumentManager |
||
50 | */ |
||
51 | private $dm; |
||
52 | |||
53 | /** |
||
54 | * The ClassMetadata instance. |
||
55 | * |
||
56 | * @var ClassMetadata |
||
57 | */ |
||
58 | private $class; |
||
59 | |||
60 | /** |
||
61 | * Whether to hydrate results as document class instances. |
||
62 | * |
||
63 | * @var boolean |
||
64 | */ |
||
65 | private $hydrate = true; |
||
66 | |||
67 | /** |
||
68 | * Array of primer Closure instances. |
||
69 | * |
||
70 | * @var array |
||
71 | */ |
||
72 | private $primers = array(); |
||
73 | |||
74 | /** |
||
75 | * Whether or not to require indexes. |
||
76 | * |
||
77 | * @var boolean |
||
78 | */ |
||
79 | private $requireIndexes; |
||
80 | |||
81 | /** |
||
82 | * Hints for UnitOfWork behavior. |
||
83 | * |
||
84 | * @var array |
||
85 | */ |
||
86 | private $unitOfWorkHints = array(); |
||
87 | |||
88 | /** |
||
89 | * Constructor. |
||
90 | * |
||
91 | * Please note that $requireIndexes was deprecated in 1.2 and will be removed in 2.0 |
||
92 | * |
||
93 | * @param DocumentManager $dm |
||
94 | * @param ClassMetadata $class |
||
95 | * @param Collection $collection |
||
96 | * @param array $query |
||
97 | * @param array $options |
||
98 | * @param boolean $hydrate |
||
99 | * @param boolean $refresh |
||
100 | * @param array $primers |
||
101 | * @param null $requireIndexes deprecated |
||
102 | * @param boolean $readOnly |
||
103 | */ |
||
104 | 200 | 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) |
|
135 | |||
136 | /** |
||
137 | * Gets the DocumentManager instance. |
||
138 | * |
||
139 | * @return DocumentManager $dm |
||
140 | */ |
||
141 | public function getDocumentManager() |
||
145 | |||
146 | /** |
||
147 | * Gets the ClassMetadata instance. |
||
148 | * |
||
149 | * @return ClassMetadata $class |
||
150 | */ |
||
151 | public function getClass() |
||
155 | |||
156 | /** |
||
157 | * Sets whether or not to hydrate the documents to objects. |
||
158 | * |
||
159 | * @param boolean $hydrate |
||
160 | */ |
||
161 | public function setHydrate($hydrate) |
||
165 | |||
166 | /** |
||
167 | * Set whether documents should be registered in UnitOfWork. If document would |
||
168 | * already be managed it will be left intact and new instance returned. |
||
169 | * |
||
170 | * This option has no effect if hydration is disabled. |
||
171 | * |
||
172 | * @param boolean $readOnly |
||
173 | */ |
||
174 | 200 | public function setReadOnly($readOnly) |
|
178 | |||
179 | /** |
||
180 | * Set whether to refresh hydrated documents that are already in the |
||
181 | * identity map. |
||
182 | * |
||
183 | * This option has no effect if hydration is disabled. |
||
184 | * |
||
185 | * @param boolean $refresh |
||
186 | */ |
||
187 | 200 | public function setRefresh($refresh) |
|
191 | |||
192 | /** |
||
193 | * Gets the fields involved in this query. |
||
194 | * |
||
195 | * @return array $fields An array of fields names used in this query. |
||
196 | * |
||
197 | * @deprecated method was deprecated in 1.2 and will be removed in 2.0 |
||
198 | */ |
||
199 | 22 | public function getFieldsInQuery() |
|
211 | |||
212 | /** |
||
213 | * Check if this query is indexed. |
||
214 | * |
||
215 | * @return bool |
||
216 | * |
||
217 | * @deprecated method was deprecated in 1.2 and will be removed in 2.0 |
||
218 | */ |
||
219 | 8 | public function isIndexed() |
|
233 | |||
234 | /** |
||
235 | * Gets an array of the unindexed fields in this query. |
||
236 | * |
||
237 | * @return array |
||
238 | * |
||
239 | * @deprecated method was deprecated in 1.2 and will be removed in 2.0 |
||
240 | */ |
||
241 | 6 | public function getUnindexedFields() |
|
256 | |||
257 | /** |
||
258 | * Execute the query and returns the results. |
||
259 | * |
||
260 | * @throws \Doctrine\ODM\MongoDB\MongoDBException |
||
261 | * @return mixed |
||
262 | */ |
||
263 | 154 | public function execute() |
|
316 | |||
317 | /** |
||
318 | * Prepare the Cursor returned by {@link Query::execute()}. |
||
319 | * |
||
320 | * This method will wrap the base Cursor with an ODM Cursor or EagerCursor, |
||
321 | * and set the hydrate option and UnitOfWork hints. This occurs in addition |
||
322 | * to any preparation done by the base Query class. |
||
323 | * |
||
324 | * @see \Doctrine\MongoDB\Cursor::prepareCursor() |
||
325 | * @param BaseCursor $cursor |
||
326 | * @return CursorInterface |
||
327 | */ |
||
328 | 133 | protected function prepareCursor(BaseCursor $cursor) |
|
346 | |||
347 | /** |
||
348 | * Return whether queries on this document should require indexes. |
||
349 | * |
||
350 | * @return boolean |
||
351 | */ |
||
352 | 154 | private function isIndexRequired() |
|
356 | } |
||
357 |
This class constant has been deprecated.