| Conditions | 3 |
| Paths | 3 |
| Total Lines | 128 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 239 | public function search( \Aimeos\Base\Criteria\Iface $filter, array $ref = [], int &$total = null ) : \Aimeos\Map |
||
| 240 | { |
||
| 241 | /** mshop/common/manager/search/mysql |
||
| 242 | * Retrieves the records matched by the given criteria in the database |
||
| 243 | * |
||
| 244 | * @see mshop/common/manager/search/ansi |
||
| 245 | */ |
||
| 246 | |||
| 247 | /** mshop/common/manager/search/ansi |
||
| 248 | * Retrieves the records matched by the given criteria in the database |
||
| 249 | * |
||
| 250 | * Fetches the records matched by the given criteria from the |
||
| 251 | * database. The records must be from one of the sites that are |
||
| 252 | * configured via the context item. If the current site is part of |
||
| 253 | * a tree of sites, the SELECT statement can retrieve all records |
||
| 254 | * from the current site and the complete sub-tree of sites. |
||
| 255 | * |
||
| 256 | * As the records can normally be limited by criteria from sub-managers, |
||
| 257 | * their tables must be joined in the SQL context. This is done by |
||
| 258 | * using the "internaldeps" property from the definition of the ID |
||
| 259 | * column of the sub-managers. These internal dependencies specify |
||
| 260 | * the JOIN between the tables and the used columns for joining. The |
||
| 261 | * ":joins" placeholder is then replaced by the JOIN strings from |
||
| 262 | * the sub-managers. |
||
| 263 | * |
||
| 264 | * To limit the records matched, conditions can be added to the given |
||
| 265 | * criteria object. It can contain comparisons like column names that |
||
| 266 | * must match specific values which can be combined by AND, OR or NOT |
||
| 267 | * operators. The resulting string of SQL conditions replaces the |
||
| 268 | * ":cond" placeholder before the statement is sent to the database |
||
| 269 | * server. |
||
| 270 | * |
||
| 271 | * If the records that are retrieved should be ordered by one or more |
||
| 272 | * columns, the generated string of column / sort direction pairs |
||
| 273 | * replaces the ":order" placeholder. Columns of |
||
| 274 | * sub-managers can also be used for ordering the result set but then |
||
| 275 | * no index can be used. |
||
| 276 | * |
||
| 277 | * The number of returned records can be limited and can start at any |
||
| 278 | * number between the begining and the end of the result set. For that |
||
| 279 | * the ":size" and ":start" placeholders are replaced by the |
||
| 280 | * corresponding values from the criteria object. The default values |
||
| 281 | * are 0 for the start and 100 for the size value. |
||
| 282 | * |
||
| 283 | * The SQL statement should conform to the ANSI standard to be |
||
| 284 | * compatible with most relational database systems. This also |
||
| 285 | * includes using double quotes for table and column names. |
||
| 286 | * |
||
| 287 | * @param string SQL statement for searching items |
||
| 288 | * @since 2023.10 |
||
| 289 | * @category Developer |
||
| 290 | * @see mshop/common/manager/insert/ansi |
||
| 291 | * @see mshop/common/manager/update/ansi |
||
| 292 | * @see mshop/common/manager/newid/ansi |
||
| 293 | * @see mshop/common/manager/delete/ansi |
||
| 294 | * @see mshop/common/manager/count/ansi |
||
| 295 | */ |
||
| 296 | $cfgPathSearch = 'mshop/common/manager/search'; |
||
| 297 | |||
| 298 | /** mshop/common/manager/count/mysql |
||
| 299 | * Counts the number of records matched by the given criteria in the database |
||
| 300 | * |
||
| 301 | * @see mshop/common/manager/count/ansi |
||
| 302 | */ |
||
| 303 | |||
| 304 | /** mshop/common/manager/count/ansi |
||
| 305 | * Counts the number of records matched by the given criteria in the database |
||
| 306 | * |
||
| 307 | * Counts all records matched by the given criteria from the |
||
| 308 | * database. The records must be from one of the sites that are |
||
| 309 | * configured via the context item. If the current site is part of |
||
| 310 | * a tree of sites, the statement can count all records from the |
||
| 311 | * current site and the complete sub-tree of sites. |
||
| 312 | * |
||
| 313 | * As the records can normally be limited by criteria from sub-managers, |
||
| 314 | * their tables must be joined in the SQL context. This is done by |
||
| 315 | * using the "internaldeps" property from the definition of the ID |
||
| 316 | * column of the sub-managers. These internal dependencies specify |
||
| 317 | * the JOIN between the tables and the used columns for joining. The |
||
| 318 | * ":joins" placeholder is then replaced by the JOIN strings from |
||
| 319 | * the sub-managers. |
||
| 320 | * |
||
| 321 | * To limit the records matched, conditions can be added to the given |
||
| 322 | * criteria object. It can contain comparisons like column names that |
||
| 323 | * must match specific values which can be combined by AND, OR or NOT |
||
| 324 | * operators. The resulting string of SQL conditions replaces the |
||
| 325 | * ":cond" placeholder before the statement is sent to the database |
||
| 326 | * server. |
||
| 327 | * |
||
| 328 | * Both, the strings for ":joins" and for ":cond" are the same as for |
||
| 329 | * the "search" SQL statement. |
||
| 330 | * |
||
| 331 | * Contrary to the "search" statement, it doesn't return any records |
||
| 332 | * but instead the number of records that have been found. As counting |
||
| 333 | * thousands of records can be a long running task, the maximum number |
||
| 334 | * of counted records is limited for performance reasons. |
||
| 335 | * |
||
| 336 | * The SQL statement should conform to the ANSI standard to be |
||
| 337 | * compatible with most relational database systems. This also |
||
| 338 | * includes using double quotes for table and column names. |
||
| 339 | * |
||
| 340 | * @param string SQL statement for counting items |
||
| 341 | * @since 2023.10 |
||
| 342 | * @category Developer |
||
| 343 | * @see mshop/common/manager/insert/ansi |
||
| 344 | * @see mshop/common/manager/update/ansi |
||
| 345 | * @see mshop/common/manager/newid/ansi |
||
| 346 | * @see mshop/common/manager/delete/ansi |
||
| 347 | * @see mshop/common/manager/search/ansi |
||
| 348 | */ |
||
| 349 | $cfgPathCount = 'mshop/common/manager/count'; |
||
| 350 | |||
| 351 | $items = []; |
||
| 352 | $prefix = $this->getPrefix(); |
||
| 353 | $level = $this->getSiteMode(); |
||
| 354 | $required = [$this->getSearchKey()]; |
||
| 355 | $conn = $this->context()->db( $this->getResourceName() ); |
||
| 356 | |||
| 357 | $results = $this->searchItemsBase( $conn, $filter, $cfgPathSearch, $cfgPathCount, $required, $total, $level ); |
||
| 358 | |||
| 359 | while( $row = $results->fetch() ) |
||
| 360 | { |
||
| 361 | if( $item = $this->applyFilter( $this->create( $row ) ) ) { |
||
| 362 | $items[$row[$prefix . 'id']] = $item; |
||
| 363 | } |
||
| 364 | } |
||
| 365 | |||
| 366 | return map( $items ); |
||
| 367 | } |
||
| 439 |