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 | * Hints for UnitOfWork behavior. |
||
76 | * |
||
77 | * @var array |
||
78 | */ |
||
79 | private $unitOfWorkHints = array(); |
||
80 | |||
81 | /** |
||
82 | * Constructor. |
||
83 | * |
||
84 | * Please note that $requireIndexes was deprecated in 1.2 and will be removed in 2.0 |
||
85 | * |
||
86 | * @param DocumentManager $dm |
||
87 | * @param ClassMetadata $class |
||
88 | * @param Collection $collection |
||
89 | * @param array $query |
||
90 | * @param array $options |
||
91 | * @param boolean $hydrate |
||
92 | * @param boolean $refresh |
||
93 | * @param array $primers |
||
94 | * @param boolean $readOnly |
||
95 | */ |
||
96 | 178 | public function __construct(DocumentManager $dm, ClassMetadata $class, Collection $collection, array $query = array(), array $options = array(), $hydrate = true, $refresh = false, array $primers = array(), $readOnly = false) |
|
126 | |||
127 | /** |
||
128 | * Gets the DocumentManager instance. |
||
129 | * |
||
130 | * @return DocumentManager $dm |
||
131 | */ |
||
132 | public function getDocumentManager() |
||
136 | |||
137 | /** |
||
138 | * Gets the ClassMetadata instance. |
||
139 | * |
||
140 | * @return ClassMetadata $class |
||
141 | */ |
||
142 | public function getClass() |
||
146 | |||
147 | /** |
||
148 | * Sets whether or not to hydrate the documents to objects. |
||
149 | * |
||
150 | * @param boolean $hydrate |
||
151 | */ |
||
152 | public function setHydrate($hydrate) |
||
156 | |||
157 | /** |
||
158 | * Set whether documents should be registered in UnitOfWork. If document would |
||
159 | * already be managed it will be left intact and new instance returned. |
||
160 | * |
||
161 | * This option has no effect if hydration is disabled. |
||
162 | * |
||
163 | * @param boolean $readOnly |
||
164 | */ |
||
165 | 178 | public function setReadOnly($readOnly) |
|
169 | |||
170 | /** |
||
171 | * Set whether to refresh hydrated documents that are already in the |
||
172 | * identity map. |
||
173 | * |
||
174 | * This option has no effect if hydration is disabled. |
||
175 | * |
||
176 | * @param boolean $refresh |
||
177 | */ |
||
178 | 178 | public function setRefresh($refresh) |
|
182 | |||
183 | /** |
||
184 | * Execute the query and returns the results. |
||
185 | * |
||
186 | * @throws \Doctrine\ODM\MongoDB\MongoDBException |
||
187 | * @return mixed |
||
188 | */ |
||
189 | 148 | public function execute() |
|
238 | |||
239 | /** |
||
240 | * Prepare the Cursor returned by {@link Query::execute()}. |
||
241 | * |
||
242 | * This method will wrap the base Cursor with an ODM Cursor or EagerCursor, |
||
243 | * and set the hydrate option and UnitOfWork hints. This occurs in addition |
||
244 | * to any preparation done by the base Query class. |
||
245 | * |
||
246 | * @see \Doctrine\MongoDB\Cursor::prepareCursor() |
||
247 | * @param BaseCursor $cursor |
||
248 | * @return CursorInterface |
||
249 | */ |
||
250 | 132 | protected function prepareCursor(BaseCursor $cursor) |
|
268 | } |
||
269 |
This class constant has been deprecated.