| Conditions | 4 |
| Paths | 4 |
| Total Lines | 123 |
| Code Lines | 88 |
| 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 |
||
| 31 | public function up() |
||
| 32 | { |
||
| 33 | $this->info( 'Adding service performance data', 'v' ); |
||
| 34 | |||
| 35 | |||
| 36 | $services = [ |
||
| 37 | 'delivery' => [ |
||
| 38 | 'pickup' => [ |
||
| 39 | 'name' => 'Pickup', |
||
| 40 | 'short' => 'Pick-up at one of our local stores', |
||
| 41 | 'image' => 'https://demo.aimeos.org/media/service/pickup.png', |
||
| 42 | 'provider' => 'Standard', |
||
| 43 | 'costs' => '0.00', |
||
| 44 | ], |
||
| 45 | 'dhl' => [ |
||
| 46 | 'name' => 'DHL', |
||
| 47 | 'short' => 'Delivery within three days by DHL', |
||
| 48 | 'image' => 'https://demo.aimeos.org/media/service/dhl.png', |
||
| 49 | 'provider' => 'Standard', |
||
| 50 | 'costs' => '3.90', |
||
| 51 | ], |
||
| 52 | 'fedex' => [ |
||
| 53 | 'name' => 'Fedex', |
||
| 54 | 'short' => 'Delivery within two days by Fedex', |
||
| 55 | 'image' => 'https://demo.aimeos.org/media/service/fedex.png', |
||
| 56 | 'provider' => 'Standard', |
||
| 57 | 'costs' => '6.90', |
||
| 58 | ], |
||
| 59 | 'tnt' => [ |
||
| 60 | 'name' => 'TNT', |
||
| 61 | 'short' => 'Delivery within one day by TNT', |
||
| 62 | 'image' => 'https://demo.aimeos.org/media/service/tnt.png', |
||
| 63 | 'provider' => 'Standard', |
||
| 64 | 'costs' => '9.90', |
||
| 65 | ], |
||
| 66 | ], |
||
| 67 | 'payment' => [ |
||
| 68 | 'invoice' => [ |
||
| 69 | 'name' => 'Invoice', |
||
| 70 | 'short' => 'Pay by invoice within 14 days', |
||
| 71 | 'image' => 'https://demo.aimeos.org/media/service/payment-in-advance.png', |
||
| 72 | 'provider' => 'PostPay', |
||
| 73 | 'costs' => '0.00', |
||
| 74 | ], |
||
| 75 | 'directdebit' => [ |
||
| 76 | 'name' => 'Direct debit', |
||
| 77 | 'short' => 'Payment via your bank account', |
||
| 78 | 'image' => 'https://demo.aimeos.org/media/service/sepa.png', |
||
| 79 | 'provider' => 'PostPay', |
||
| 80 | 'costs' => '0.00', |
||
| 81 | ], |
||
| 82 | 'cash' => [ |
||
| 83 | 'name' => 'Cash on delivery', |
||
| 84 | 'short' => 'Pay cash on delivery of the parcel', |
||
| 85 | 'image' => 'https://demo.aimeos.org/media/service/dhl-cod.png', |
||
| 86 | 'provider' => 'PrePay', |
||
| 87 | 'costs' => '8.00', |
||
| 88 | ], |
||
| 89 | 'prepay' => [ |
||
| 90 | 'name' => 'Prepayment', |
||
| 91 | 'short' => 'Pay in advance before the parcel is shipped', |
||
| 92 | 'image' => 'https://demo.aimeos.org/media/service/payment-in-advance-alternative.png', |
||
| 93 | 'provider' => 'PrePay', |
||
| 94 | 'costs' => '0.00', |
||
| 95 | ], |
||
| 96 | ], |
||
| 97 | ]; |
||
| 98 | |||
| 99 | $numServices = $this->context()->getConfig()->get( 'setup/unitperf/max-services', 100 ); |
||
|
|
|||
| 100 | |||
| 101 | $manager = \Aimeos\MShop::create( $this->context(), 'service' ); |
||
| 102 | $listManager = \Aimeos\MShop::create( $this->context(), 'service/lists' ); |
||
| 103 | $mediaManager = \Aimeos\MShop::create( $this->context(), 'media' ); |
||
| 104 | $priceManager = \Aimeos\MShop::create( $this->context(), 'price' ); |
||
| 105 | $textManager = \Aimeos\MShop::create( $this->context(), 'text' ); |
||
| 106 | |||
| 107 | $mListItem = $listManager->create()->setType( 'default' ); |
||
| 108 | $pListItem = $listManager->create()->setType( 'default' ); |
||
| 109 | $tListItem = $listManager->create()->setType( 'default' ); |
||
| 110 | |||
| 111 | $mediaItem = $mediaManager->create()->setType( 'icon' )->setMimeType( 'image/png' ); |
||
| 112 | $priceItem = $priceManager->create()->setType( 'default' )->setCurrencyId( 'EUR' ); |
||
| 113 | $textItem = $textManager->create()->setType( 'short' ); |
||
| 114 | |||
| 115 | |||
| 116 | $manager->begin(); |
||
| 117 | |||
| 118 | foreach( $services as $type => $list ) |
||
| 119 | { |
||
| 120 | $pos = 0; |
||
| 121 | $serviceItem = $manager->create()->setType( $type ); |
||
| 122 | |||
| 123 | for( $i = 0; $i < $numServices / 4; $i++ ) |
||
| 124 | { |
||
| 125 | foreach( $list as $code => $entry ) |
||
| 126 | { |
||
| 127 | $code = 'perf-pay-' . $code . '-' . str_pad( $i, 3, '0', STR_PAD_LEFT ); |
||
| 128 | |||
| 129 | $item = clone $serviceItem; |
||
| 130 | $item->setLabel( $entry['name'] ) |
||
| 131 | ->setProvider( $entry['provider'] ) |
||
| 132 | ->setPosition( $pos++ ) |
||
| 133 | ->setCode( $code ) |
||
| 134 | ->setStatus( 1 ); |
||
| 135 | |||
| 136 | $media = clone $mediaItem; |
||
| 137 | $media->setLabel( $entry['name'] )->setPreview( $entry['image'] )->setUrl( $entry['image'] ); |
||
| 138 | $item->addListItem( 'media', clone $mListItem, $media ); |
||
| 139 | |||
| 140 | $price = clone $priceItem; |
||
| 141 | $price->setLabel( $entry['name'] )->setCosts( $entry['costs'] ); |
||
| 142 | $item->addListItem( 'price', clone $pListItem, $price ); |
||
| 143 | |||
| 144 | $text = clone $textItem; |
||
| 145 | $text->setLabel( $entry['name'] )->setContent( $entry['short'] ); |
||
| 146 | $item->addListItem( 'text', clone $tListItem, $text ); |
||
| 147 | |||
| 148 | $manager->save( $item ); |
||
| 149 | } |
||
| 150 | } |
||
| 151 | } |
||
| 152 | |||
| 153 | $manager->commit(); |
||
| 154 | } |
||
| 156 |