Conditions | 8 |
Paths | 14 |
Total Lines | 53 |
Code Lines | 28 |
Lines | 16 |
Ratio | 30.19 % |
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 |
||
37 | public function perform($owner, $repo, $base, $head, $commit_message = '') |
||
38 | { |
||
39 | // Build the request path. |
||
40 | $path = '/repos/' . $owner . '/' . $repo . '/merges'; |
||
41 | |||
42 | $data = new \stdClass; |
||
43 | |||
44 | $data->base = $base; |
||
45 | $data->head = $head; |
||
46 | |||
47 | if ($commit_message) |
||
48 | { |
||
49 | $data->commit_message = $commit_message; |
||
50 | } |
||
51 | |||
52 | // Send the request. |
||
53 | $response = $this->client->post($this->fetchUrl($path), json_encode($data)); |
||
54 | |||
55 | switch ($response->code) |
||
56 | { |
||
57 | case '201': |
||
58 | // Success |
||
59 | return json_decode($response->body); |
||
60 | break; |
||
|
|||
61 | |||
62 | case '204': |
||
63 | // No-op response (base already contains the head, nothing to merge) |
||
64 | throw new \UnexpectedValueException('Nothing to merge'); |
||
65 | break; |
||
66 | |||
67 | View Code Duplication | case '404': |
|
68 | // Missing base or Missing head response |
||
69 | $error = json_decode($response->body); |
||
70 | |||
71 | $message = (isset($error->message)) ? $error->message : 'Missing base or head: ' . $response->code; |
||
72 | |||
73 | throw new \UnexpectedValueException($message); |
||
74 | break; |
||
75 | |||
76 | View Code Duplication | case '409': |
|
77 | // Merge conflict response |
||
78 | $error = json_decode($response->body); |
||
79 | |||
80 | $message = (isset($error->message)) ? $error->message : 'Merge conflict ' . $response->code; |
||
81 | |||
82 | throw new \UnexpectedValueException($message); |
||
83 | break; |
||
84 | |||
85 | default : |
||
86 | throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); |
||
87 | break; |
||
88 | } |
||
89 | } |
||
90 | } |
||
91 |
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.