Conditions | 10 |
Paths | 171 |
Total Lines | 60 |
Code Lines | 32 |
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 |
||
43 | public function up() |
||
44 | { |
||
45 | $this->info( 'Processing catalog demo data' ); |
||
46 | |||
47 | $context = $this->context(); |
||
|
|||
48 | $value = $context->config()->get( 'setup/default/demo', '' ); |
||
49 | |||
50 | if( $value === '' ) |
||
51 | { |
||
52 | $this->status( 'OK' ); |
||
53 | return; |
||
54 | } |
||
55 | |||
56 | |||
57 | $item = null; |
||
58 | $manager = \Aimeos\MShop::create( $context, 'catalog' ); |
||
59 | |||
60 | try |
||
61 | { |
||
62 | // Don't delete the catalog node because users are likely use it for production |
||
63 | $item = $manager->getTree( null, [], \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ); |
||
64 | |||
65 | $this->removeItems( $item->getId(), 'catalog/lists', 'catalog', 'media' ); |
||
66 | $this->removeItems( $item->getId(), 'catalog/lists', 'catalog', 'text' ); |
||
67 | $this->removeListItems( $item->getId(), 'catalog/lists', 'product' ); |
||
68 | } |
||
69 | catch( \Exception $e ) {; } // If no root node was already inserted into the database |
||
70 | |||
71 | $search = $manager->filter(); |
||
72 | $search->setConditions( $search->compare( '=~', 'catalog.code', 'demo-' ) ); |
||
73 | $manager->delete( $manager->search( $search )->getId()->toArray() ); |
||
74 | |||
75 | |||
76 | if( $value === '1' ) |
||
77 | { |
||
78 | $ds = DIRECTORY_SEPARATOR; |
||
79 | $path = __DIR__ . $ds . 'data' . $ds . 'demo-catalog.php'; |
||
80 | |||
81 | if( ( $data = include( $path ) ) == false ) { |
||
82 | throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for catalog domain', $path ) ); |
||
83 | } |
||
84 | |||
85 | if( $item === null ) { |
||
86 | $item = $manager->insert( $manager->create()->fromArray( $data ) ); |
||
87 | } |
||
88 | |||
89 | if( isset( $data['media'] ) ) { |
||
90 | $this->addMedia( $item->getId(), $data['media'], 'catalog' ); |
||
91 | } |
||
92 | |||
93 | if( isset( $data['product'] ) ) { |
||
94 | $this->addProducts( $item->getId(), $data['product'], 'catalog' ); |
||
95 | } |
||
96 | |||
97 | if( isset( $data['text'] ) ) { |
||
98 | $this->addTexts( $item->getId(), $data['text'], 'catalog' ); |
||
99 | } |
||
100 | |||
101 | if( isset( $data['catalog'] ) ) { |
||
102 | $this->addCatalog( $item->getId(), $data['catalog'], 'catalog' ); |
||
103 | } |
||
141 | } |