| Conditions | 7 |
| Paths | 11 |
| Total Lines | 57 |
| Code Lines | 35 |
| 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 |
||
| 57 | protected function addDemoData() |
||
| 58 | { |
||
| 59 | $num = 0; |
||
| 60 | $paystatus = [ |
||
| 61 | \Aimeos\MShop\Order\Item\Base::PAY_RECEIVED, |
||
| 62 | \Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED, |
||
| 63 | \Aimeos\MShop\Order\Item\Base::PAY_RECEIVED, |
||
| 64 | \Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED, |
||
| 65 | \Aimeos\MShop\Order\Item\Base::PAY_PENDING |
||
| 66 | ]; |
||
| 67 | $customer = \Aimeos\MShop::create( $this->context(), 'customer' )->find( '[email protected]' ); |
||
| 68 | |||
| 69 | foreach( $this->locales() as $locale ) |
||
| 70 | { |
||
| 71 | $lcontext = clone $this->context(); |
||
| 72 | $lcontext->setLocale( $locale ); |
||
| 73 | |||
| 74 | $products = $this->products( $lcontext ); |
||
| 75 | $services = $this->services( $lcontext ); |
||
| 76 | |||
| 77 | $manager = \Aimeos\MShop::create( $lcontext, 'order' ); |
||
| 78 | $manager->begin(); |
||
| 79 | |||
| 80 | for( $i = 0; $i < 10; $i++ ) |
||
| 81 | { |
||
| 82 | for( $j = 0; $j < floor( $i / 4 ) + 1; $j++ ) |
||
| 83 | { |
||
| 84 | $lcontext->setDateTime( date( 'Y-m-d H:i:s', time() + ( -9 + $i ) * 86400 - 15000 + ( $num % 10 ) * 1357 ) ); |
||
| 85 | |||
| 86 | $item = $manager->create() |
||
| 87 | ->setChannel( 'demo' ) |
||
| 88 | ->setCustomerId( $customer->getId() ) |
||
| 89 | ->setStatusPayment( $paystatus[$num % 5] ) |
||
| 90 | ->setDatePayment( $lcontext->datetime() ) |
||
| 91 | ->setLocale( $locale ); |
||
| 92 | |||
| 93 | foreach( map( $services->get( 'delivery', [] ) )->random( 1 ) as $service ) { |
||
| 94 | $item->addService( clone $service, 'delivery' ); |
||
| 95 | } |
||
| 96 | |||
| 97 | foreach( map( $services->get( 'payment', [] ) )->random( 1 ) as $service ) { |
||
| 98 | $item->addService( clone $service, 'payment' ); |
||
| 99 | } |
||
| 100 | |||
| 101 | foreach( $products->random( rand( 1, 2 ) ) as $product ) { |
||
| 102 | $item->addProduct( clone $product ); |
||
| 103 | } |
||
| 104 | |||
| 105 | $item->addAddress( $this->address( $customer->getPaymentAddress(), $num ), 'payment' ); |
||
| 106 | |||
| 107 | $manager->save( $item ); |
||
| 108 | ++$num; |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | $manager->commit(); |
||
| 113 | $num += 7; |
||
| 114 | } |
||
| 206 |