| Conditions | 5 |
| Paths | 8 |
| Total Lines | 61 |
| Code Lines | 30 |
| 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 |
||
| 51 | public function run() |
||
| 52 | { |
||
| 53 | $context = $this->getContext(); |
||
| 54 | $config = $context->getConfig(); |
||
| 55 | $logger = $context->getLogger(); |
||
| 56 | |||
| 57 | /** controller/common/subscription/process/processors |
||
| 58 | * List of processor names that should be executed for subscriptions |
||
| 59 | * |
||
| 60 | * For each subscription a number of processors for different tasks can be executed. |
||
| 61 | * They can for example add a group to the customers' account during the customer |
||
| 62 | * has an active subscribtion. |
||
| 63 | * |
||
| 64 | * @param array List of processor names |
||
| 65 | * @since 2018.04 |
||
| 66 | * @category Developer |
||
| 67 | */ |
||
| 68 | $names = (array) $config->get( 'controller/common/subscription/process/processors', [] ); |
||
| 69 | |||
| 70 | $processors = $this->getProcessors( $names ); |
||
| 71 | $manager = \Aimeos\MShop\Factory::createManager( $context, 'subscription' ); |
||
| 72 | |||
| 73 | $search = $manager->createSearch( true ); |
||
| 74 | $expr = [ |
||
| 75 | $search->compare( '<', 'subscription.dateend', date( 'Y-m-d' ) ), |
||
| 76 | $search->getConditions(), |
||
| 77 | ]; |
||
| 78 | $search->setConditions( $search->combine( '&&', $expr ) ); |
||
| 79 | $search->setSortations( [$search->sort( '+', 'subscription.id' )] ); |
||
| 80 | |||
| 81 | $start = 0; |
||
| 82 | |||
| 83 | do |
||
| 84 | { |
||
| 85 | $search->setSlice( $start, 100 ); |
||
| 86 | $items = $manager->searchItems( $search ); |
||
| 87 | |||
| 88 | foreach( $items as $item ) |
||
| 89 | { |
||
| 90 | try |
||
| 91 | { |
||
| 92 | foreach( $processors as $processor ) { |
||
| 93 | $processor->end( $item ); |
||
| 94 | } |
||
| 95 | |||
| 96 | $item->setStatus( 0 ); |
||
| 97 | $manager->saveItem( $item ); |
||
| 98 | } |
||
| 99 | catch( \Exception $e ) |
||
| 100 | { |
||
| 101 | $msg = 'Unable to process subscription with ID "%1$S": %2$s'; |
||
| 102 | $logger->log( sprintf( $msg, $item->getId(), $e->getMessage() ) ); |
||
| 103 | $logger->log( $e->getTraceAsString() ); |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | $count = count( $items ); |
||
| 108 | $start += $count; |
||
| 109 | } |
||
| 110 | while( $count === $search->getSliceSize() ); |
||
| 111 | } |
||
| 112 | } |
||
| 113 |