| Conditions | 9 |
| Paths | 23 |
| Total Lines | 70 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 32 | public function up() |
||
| 33 | { |
||
| 34 | $this->info( 'Processing service demo data', 'v' ); |
||
| 35 | |||
| 36 | $context = $this->context(); |
||
|
|
|||
| 37 | $value = $context->getConfig()->get( 'setup/default/demo', '' ); |
||
| 38 | |||
| 39 | if( $value === '' ) { |
||
| 40 | return; |
||
| 41 | } |
||
| 42 | |||
| 43 | |||
| 44 | $manager = \Aimeos\MShop::create( $context, 'service' ); |
||
| 45 | |||
| 46 | $search = $manager->filter(); |
||
| 47 | $search->setConditions( $search->compare( '=~', 'service.code', 'demo-' ) ); |
||
| 48 | $services = $manager->search( $search ); |
||
| 49 | |||
| 50 | foreach( $services as $item ) |
||
| 51 | { |
||
| 52 | $this->removeItems( $item->getId(), 'service/lists', 'service', 'media' ); |
||
| 53 | $this->removeItems( $item->getId(), 'service/lists', 'service', 'price' ); |
||
| 54 | $this->removeItems( $item->getId(), 'service/lists', 'service', 'text' ); |
||
| 55 | } |
||
| 56 | |||
| 57 | $manager->delete( $services->toArray() ); |
||
| 58 | |||
| 59 | |||
| 60 | if( $value === '1' ) |
||
| 61 | { |
||
| 62 | $ds = DIRECTORY_SEPARATOR; |
||
| 63 | $path = __DIR__ . $ds . 'data' . $ds . 'demo-service.php'; |
||
| 64 | |||
| 65 | if( ( $data = include( $path ) ) == false ) { |
||
| 66 | throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for service domain', $path ) ); |
||
| 67 | } |
||
| 68 | |||
| 69 | foreach( $data as $entry ) |
||
| 70 | { |
||
| 71 | $item = $manager->create(); |
||
| 72 | $item->setType( $entry['type'] ); |
||
| 73 | $item->setCode( $entry['code'] ); |
||
| 74 | $item->setLabel( $entry['label'] ); |
||
| 75 | $item->setProvider( $entry['provider'] ); |
||
| 76 | $item->setPosition( $entry['position'] ); |
||
| 77 | $item->setConfig( $entry['config'] ); |
||
| 78 | $item->setStatus( $entry['status'] ); |
||
| 79 | |||
| 80 | $manager->save( $item ); |
||
| 81 | |||
| 82 | if( isset( $entry['media'] ) ) { |
||
| 83 | $this->addMedia( $item->getId(), $entry['media'], 'service' ); |
||
| 84 | } |
||
| 85 | |||
| 86 | if( isset( $entry['price'] ) ) { |
||
| 87 | $this->addPrices( $item->getId(), $entry['price'], 'service' ); |
||
| 88 | } |
||
| 89 | |||
| 90 | if( isset( $entry['text'] ) ) { |
||
| 91 | $this->addTexts( $item->getId(), $entry['text'], 'service' ); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |
||
| 95 | } |
||
| 96 | } |
||
| 97 |