Conditions | 3 |
Paths | 9 |
Total Lines | 122 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
162 | public function searchItems( \Aimeos\MW\Criteria\Iface $search, array $ref = array(), &$total = null ) |
||
163 | { |
||
164 | $map = array(); |
||
165 | $context = $this->getContext(); |
||
166 | |||
167 | $dbm = $context->getDatabaseManager(); |
||
168 | $dbname = $this->getResourceName(); |
||
169 | $conn = $dbm->acquire( $dbname ); |
||
170 | |||
171 | try |
||
172 | { |
||
173 | $required = array( 'customer.group' ); |
||
174 | $level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL; |
||
175 | |||
176 | /** mshop/customer/manager/group/typo3/search |
||
177 | * Retrieves the records matched by the given criteria in the database |
||
178 | * |
||
179 | * Fetches the records matched by the given criteria from the customer |
||
180 | * database. The records must be from one of the sites that are |
||
181 | * configured via the context item. If the current site is part of |
||
182 | * a tree of sites, the SELECT statement can retrieve all records |
||
183 | * from the current site and the complete sub-tree of sites. |
||
184 | * |
||
185 | * As the records can normally be limited by criteria from sub-managers, |
||
186 | * their tables must be joined in the SQL context. This is done by |
||
187 | * using the "internaldeps" property from the definition of the ID |
||
188 | * column of the sub-managers. These internal dependencies specify |
||
189 | * the JOIN between the tables and the used columns for joining. The |
||
190 | * ":joins" placeholder is then replaced by the JOIN strings from |
||
191 | * the sub-managers. |
||
192 | * |
||
193 | * To limit the records matched, conditions can be added to the given |
||
194 | * criteria object. It can contain comparisons like column names that |
||
195 | * must match specific values which can be combined by AND, OR or NOT |
||
196 | * operators. The resulting string of SQL conditions replaces the |
||
197 | * ":cond" placeholder before the statement is sent to the database |
||
198 | * server. |
||
199 | * |
||
200 | * If the records that are retrieved should be ordered by one or more |
||
201 | * columns, the generated string of column / sort direction pairs |
||
202 | * replaces the ":order" placeholder. In case no ordering is required, |
||
203 | * the complete ORDER BY part including the "\/*-orderby*\/...\/*orderby-*\/" |
||
204 | * markers is removed to speed up retrieving the records. Columns of |
||
205 | * sub-managers can also be used for ordering the result set but then |
||
206 | * no index can be used. |
||
207 | * |
||
208 | * The number of returned records can be limited and can start at any |
||
209 | * number between the begining and the end of the result set. For that |
||
210 | * the ":size" and ":start" placeholders are replaced by the |
||
211 | * corresponding values from the criteria object. The default values |
||
212 | * are 0 for the start and 100 for the size value. |
||
213 | * |
||
214 | * The SQL statement should conform to the ANSI standard to be |
||
215 | * compatible with most relational database systems. This also |
||
216 | * includes using double quotes for table and column names. |
||
217 | * |
||
218 | * @param string SQL statement for searching items |
||
219 | * @since 2015.08 |
||
220 | * @category Developer |
||
221 | * @see mshop/customer/manager/group/typo3/count |
||
222 | */ |
||
223 | $cfgPathSearch = 'mshop/customer/manager/group/typo3/search'; |
||
224 | |||
225 | /** mshop/customer/manager/group/typo3/count |
||
226 | * Counts the number of records matched by the given criteria in the database |
||
227 | * |
||
228 | * Counts all records matched by the given criteria from the customer |
||
229 | * database. The records must be from one of the sites that are |
||
230 | * configured via the context item. If the current site is part of |
||
231 | * a tree of sites, the statement can count all records from the |
||
232 | * current site and the complete sub-tree of sites. |
||
233 | * |
||
234 | * As the records can normally be limited by criteria from sub-managers, |
||
235 | * their tables must be joined in the SQL context. This is done by |
||
236 | * using the "internaldeps" property from the definition of the ID |
||
237 | * column of the sub-managers. These internal dependencies specify |
||
238 | * the JOIN between the tables and the used columns for joining. The |
||
239 | * ":joins" placeholder is then replaced by the JOIN strings from |
||
240 | * the sub-managers. |
||
241 | * |
||
242 | * To limit the records matched, conditions can be added to the given |
||
243 | * criteria object. It can contain comparisons like column names that |
||
244 | * must match specific values which can be combined by AND, OR or NOT |
||
245 | * operators. The resulting string of SQL conditions replaces the |
||
246 | * ":cond" placeholder before the statement is sent to the database |
||
247 | * server. |
||
248 | * |
||
249 | * Both, the strings for ":joins" and for ":cond" are the same as for |
||
250 | * the "search" SQL statement. |
||
251 | * |
||
252 | * Contrary to the "search" statement, it doesn't return any records |
||
253 | * but instead the number of records that have been found. As counting |
||
254 | * thousands of records can be a long running task, the maximum number |
||
255 | * of counted records is limited for performance reasons. |
||
256 | * |
||
257 | * The SQL statement should conform to the ANSI standard to be |
||
258 | * compatible with most relational database systems. This also |
||
259 | * includes using double quotes for table and column names. |
||
260 | * |
||
261 | * @param string SQL statement for counting items |
||
262 | * @since 2015.08 |
||
263 | * @category Developer |
||
264 | * @see mshop/customer/manager/group/typo3/search |
||
265 | */ |
||
266 | $cfgPathCount = 'mshop/customer/manager/group/typo3/count'; |
||
267 | |||
268 | $results = $this->searchItemsBase( $conn, $search, $cfgPathSearch, $cfgPathCount, $required, $total, $level ); |
||
269 | |||
270 | while( ( $row = $results->fetch() ) !== false ) { |
||
271 | $map[$row['customer.group.id']] = $this->createItemBase( $row ); |
||
272 | } |
||
273 | |||
274 | $dbm->release( $conn, $dbname ); |
||
275 | } |
||
276 | catch( \Exception $e ) |
||
277 | { |
||
278 | $dbm->release( $conn, $dbname ); |
||
279 | throw $e; |
||
280 | } |
||
281 | |||
282 | return $map; |
||
283 | } |
||
284 | |||
309 |