Conditions | 10 |
Paths | 61 |
Total Lines | 44 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 1 |
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 |
||
20 | public function actionGetBots(Request $request, $botId) |
||
|
|||
21 | { |
||
22 | $response = array( |
||
23 | 'status' => false |
||
24 | ); |
||
25 | try { |
||
26 | $brainPath = __DIR__ . '/../../../app/brains/'; |
||
27 | $files = glob($brainPath .(empty($botId) ? '*' : $botId), GLOB_ONLYDIR); |
||
28 | if (empty($files)) { |
||
29 | return $this->render(array( |
||
30 | 'status' => true, |
||
31 | 'data' => '', |
||
32 | 'message' => 'No bot available' |
||
33 | )); |
||
34 | } |
||
35 | |||
36 | $response = array( |
||
37 | 'status' => true |
||
38 | ); |
||
39 | $data = array(); |
||
40 | foreach ($files as $file) { |
||
41 | $bot = array(); |
||
42 | $identityFile = $file . '/identity.json'; |
||
43 | if (is_file($identityFile) && (null != ($identity = loadJsonFile($identityFile, 'UTF-8')))) { |
||
44 | $bot['id'] = $identity->id; |
||
45 | $bot['name'] = $identity->name; |
||
46 | $bot['pseudo'] = (! empty($identity->pseudo) ? $identity->pseudo : ucfirst($identity->name)); |
||
47 | $bot['conceptorName'] = (! empty($identity->conceptorName) ? $identity->conceptorName : 'the Ancients'); |
||
48 | $bot['birth'] = new \DateTime($identity->birthday); |
||
49 | $bot['timezone'] = @$identity->timezone; |
||
50 | $bot['desc'] = $bot['name'] . (! empty($identity->pseudo) ? ' alias ' . $identity->pseudo : '') . ': made the ' . $bot['birth']->format('jS \o\f F Y') . ' by ' . $bot['conceptorName']; |
||
51 | } |
||
52 | else { |
||
53 | $bot['name'] = $file; |
||
54 | $bot['message'] = 'No identity description for this bot...'; |
||
55 | } |
||
56 | $data[] = $bot; |
||
57 | } |
||
58 | $response['data'] = $data; |
||
59 | } catch (\Exception $e) { |
||
60 | $response['message'] = 'Error during process: ' . $e->getMessage(); |
||
61 | } |
||
62 | return $this->render($response); |
||
63 | } |
||
64 | |||
130 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.