| Conditions | 14 |
| Paths | 4 |
| Total Lines | 78 |
| Code Lines | 47 |
| Lines | 19 |
| Ratio | 24.36 % |
| 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 |
||
| 68 | public function search(Application $app, Request $request) |
||
|
|
|||
| 69 | { |
||
| 70 | // Acquire downloadable plug-in information from owners store |
||
| 71 | $success = 0; |
||
| 72 | $items = array(); |
||
| 73 | $promotionItems = array(); |
||
| 74 | $message = ''; |
||
| 75 | // Owner's store communication |
||
| 76 | $url = $this->appConfig['owners_store_url'].'?method=list'; |
||
| 77 | list($json, $info) = $this->getRequestApi($url, $app); |
||
| 78 | if ($json === false) { |
||
| 79 | $message = $this->getResponseErrorMessage($info); |
||
| 80 | } else { |
||
| 81 | $data = json_decode($json, true); |
||
| 82 | if (isset($data['success'])) { |
||
| 83 | $success = $data['success']; |
||
| 84 | if ($success == '1') { |
||
| 85 | $items = array(); |
||
| 86 | // Check plugin installed |
||
| 87 | $arrPluginInstalled = $this->pluginRepository->findAll(); |
||
| 88 | // Update_status 1 : not install/purchased 、2 : Installed、 3 : Update、4 : paid purchase |
||
| 89 | foreach ($data['item'] as $item) { |
||
| 90 | // Not install/purchased |
||
| 91 | $item['update_status'] = 1; |
||
| 92 | /** @var Plugin $plugin */ |
||
| 93 | foreach ($arrPluginInstalled as $plugin) { |
||
| 94 | if ($plugin->getSource() == $item['product_id']) { |
||
| 95 | // Need update |
||
| 96 | $item['update_status'] = 3; |
||
| 97 | if ($plugin->getVersion() == $item['version']) { |
||
| 98 | // Installed |
||
| 99 | $item['update_status'] = 2; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | } |
||
| 103 | $items[] = $item; |
||
| 104 | } |
||
| 105 | |||
| 106 | // EC-CUBE version check |
||
| 107 | View Code Duplication | foreach ($items as &$item) { |
|
| 108 | // Not applicable version |
||
| 109 | $item['version_check'] = 0; |
||
| 110 | if (in_array(Constant::VERSION, $item['eccube_version'])) { |
||
| 111 | // Match version |
||
| 112 | $item['version_check'] = 1; |
||
| 113 | } |
||
| 114 | if ($item['price'] != '0' && $item['purchased'] == '0') { |
||
| 115 | // Not purchased with paid items |
||
| 116 | $item['update_status'] = 4; |
||
| 117 | } |
||
| 118 | } |
||
| 119 | unset($item); |
||
| 120 | |||
| 121 | // Promotion item |
||
| 122 | $i = 0; |
||
| 123 | View Code Duplication | foreach ($items as $item) { |
|
| 124 | if ($item['promotion'] == 1) { |
||
| 125 | $promotionItems[] = $item; |
||
| 126 | unset($items[$i]); |
||
| 127 | } |
||
| 128 | $i++; |
||
| 129 | } |
||
| 130 | } else { |
||
| 131 | $message = $data['error_code'] . ' : ' . $data['error_message']; |
||
| 132 | } |
||
| 133 | } else { |
||
| 134 | $success = 0; |
||
| 135 | $message = "EC-CUBEオーナーズストアにエラーが発生しています。"; |
||
| 136 | } |
||
| 137 | } |
||
| 138 | |||
| 139 | return [ |
||
| 140 | 'success' => $success, |
||
| 141 | 'items' => $items, |
||
| 142 | 'promotionItems' => $promotionItems, |
||
| 143 | 'message' => $message, |
||
| 144 | ]; |
||
| 145 | } |
||
| 146 | |||
| 233 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.