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