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