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 |
||
43 | public function migrate() |
||
44 | { |
||
45 | $this->msg( 'Processing service demo data', 0 ); |
||
46 | |||
47 | $context = $this->getContext(); |
||
48 | $value = $context->getConfig()->get( 'setup/default/demo', '' ); |
||
49 | |||
50 | if( $value === '' ) |
||
51 | { |
||
52 | $this->status( 'OK' ); |
||
53 | return; |
||
54 | } |
||
55 | |||
56 | |||
57 | $manager = \Aimeos\MShop::create( $context, 'service' ); |
||
58 | |||
59 | $search = $manager->createSearch(); |
||
60 | $search->setConditions( $search->compare( '=~', 'service.code', 'demo-' ) ); |
||
61 | $services = $manager->searchItems( $search ); |
||
62 | |||
63 | foreach( $services as $item ) |
||
64 | { |
||
65 | $this->removeItems( $item->getId(), 'service/lists', 'service', 'media' ); |
||
66 | $this->removeItems( $item->getId(), 'service/lists', 'service', 'price' ); |
||
67 | $this->removeItems( $item->getId(), 'service/lists', 'service', 'text' ); |
||
68 | } |
||
69 | |||
70 | $manager->deleteItems( array_keys( $services ) ); |
||
71 | |||
72 | |||
73 | if( $value === '1' ) |
||
74 | { |
||
75 | $ds = DIRECTORY_SEPARATOR; |
||
76 | $path = __DIR__ . $ds . 'data' . $ds . 'demo-service.php'; |
||
77 | |||
78 | if( ( $data = include( $path ) ) == false ) { |
||
79 | throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for service domain', $path ) ); |
||
80 | } |
||
81 | |||
82 | foreach( $data as $entry ) |
||
83 | { |
||
84 | $item = $manager->createItem(); |
||
85 | $item->setType( $entry['type'] ); |
||
86 | $item->setCode( $entry['code'] ); |
||
87 | $item->setLabel( $entry['label'] ); |
||
88 | $item->setProvider( $entry['provider'] ); |
||
|
|||
89 | $item->setPosition( $entry['position'] ); |
||
90 | $item->setConfig( $entry['config'] ); |
||
91 | $item->setStatus( $entry['status'] ); |
||
92 | |||
93 | $manager->saveItem( $item ); |
||
94 | |||
95 | if( isset( $entry['media'] ) ) { |
||
96 | $this->addMedia( $item->getId(), $entry['media'], 'service' ); |
||
97 | } |
||
98 | |||
99 | if( isset( $entry['price'] ) ) { |
||
100 | $this->addPrices( $item->getId(), $entry['price'], 'service' ); |
||
101 | } |
||
102 | |||
103 | if( isset( $entry['text'] ) ) { |
||
104 | $this->addTexts( $item->getId(), $entry['text'], 'service' ); |
||
105 | } |
||
106 | } |
||
107 | |||
108 | $this->status( 'added' ); |
||
109 | } |
||
110 | else |
||
111 | { |
||
112 | $this->status( 'removed' ); |
||
113 | } |
||
116 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.