| Conditions | 8 |
| Paths | 29 |
| Total Lines | 71 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 49 | public function run() |
||
| 50 | { |
||
| 51 | $context = $this->context(); |
||
| 52 | |||
| 53 | $serviceManager = \Aimeos\MShop::create( $context, 'service' ); |
||
| 54 | $serviceSearch = $serviceManager->filter()->add( ['service.type' => 'payment'] ); |
||
| 55 | |||
| 56 | $orderManager = \Aimeos\MShop::create( $context, 'order' ); |
||
| 57 | $orderSearch = $orderManager->filter(); |
||
| 58 | $start = 0; |
||
| 59 | |||
| 60 | do |
||
| 61 | { |
||
| 62 | $serviceItems = $serviceManager->search( $serviceSearch ); |
||
| 63 | |||
| 64 | foreach( $serviceItems as $serviceItem ) |
||
| 65 | { |
||
| 66 | try |
||
| 67 | { |
||
| 68 | $serviceProvider = $serviceManager->getProvider( $serviceItem, $serviceItem->getType() ); |
||
| 69 | |||
| 70 | if( !$serviceProvider->isImplemented( \Aimeos\MShop\Service\Provider\Payment\Base::FEAT_TRANSFER ) ) { |
||
| 71 | continue; |
||
| 72 | } |
||
| 73 | |||
| 74 | $orderSearch->setConditions( $orderSearch->and( [ |
||
| 75 | $orderSearch->compare( '<=', 'order.ctime', date( 'Y-m-d 00:00:00', time() - 86400 * $this->days() ) ), |
||
| 76 | $orderSearch->compare( '==', 'order.statuspayment', \Aimeos\MShop\Order\Item\Base::PAY_RECEIVED ), |
||
| 77 | $orderSearch->compare( '==', 'order.base.service.code', $serviceItem->getCode() ), |
||
| 78 | $orderSearch->compare( '==', 'order.base.service.type', 'payment' ) |
||
| 79 | ] ) ); |
||
| 80 | |||
| 81 | $orderStart = 0; |
||
| 82 | |||
| 83 | do |
||
| 84 | { |
||
| 85 | $orderItems = $orderManager->search( $orderSearch, $this->domains() ); |
||
| 86 | |||
| 87 | foreach( $orderItems as $orderItem ) |
||
| 88 | { |
||
| 89 | try |
||
| 90 | { |
||
| 91 | $orderManager->save( $serviceProvider->transfer( $orderItem ) ); |
||
| 92 | } |
||
| 93 | catch( \Exception $e ) |
||
| 94 | { |
||
| 95 | $str = 'Error while transferring payment for order with ID "%1$s": %2$s'; |
||
| 96 | $msg = sprintf( $str, $serviceItem->getId(), $e->getMessage() . "\n" . $e->getTraceAsString() ); |
||
| 97 | $context->logger()->error( $msg, 'order/service/transfer' ); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | $orderCount = count( $orderItems ); |
||
| 102 | $orderStart += $orderCount; |
||
| 103 | $orderSearch->slice( $orderStart ); |
||
| 104 | } |
||
| 105 | while( $orderCount >= $orderSearch->getLimit() ); |
||
| 106 | } |
||
| 107 | catch( \Exception $e ) |
||
| 108 | { |
||
| 109 | $str = 'Error while transferring payment for service with ID "%1$s": %2$s'; |
||
| 110 | $msg = sprintf( $str, $serviceItem->getId(), $e->getMessage() . "\n" . $e->getTraceAsString() ); |
||
| 111 | $context->logger()->error( $msg, 'order/service/transfer' ); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | |||
| 115 | $count = count( $serviceItems ); |
||
| 116 | $start += $count; |
||
| 117 | $serviceSearch->slice( $start ); |
||
| 118 | } |
||
| 119 | while( $count >= $serviceSearch->getLimit() ); |
||
| 120 | } |
||
| 172 |