| Conditions | 13 |
| Paths | 200 |
| Total Lines | 76 |
| Code Lines | 43 |
| 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 |
||
| 16 | public function execute() |
||
| 17 | { |
||
| 18 | $result = new \stdClass(); |
||
| 19 | |||
| 20 | $this->payLoad = $this->getPayload(); |
||
| 21 | $device_uid = ""; |
||
| 22 | if(isset($this->payLoad["device_uid"])) { |
||
| 23 | $device_uid = $this->payLoad["device_uid"]; |
||
| 24 | } |
||
| 25 | |||
| 26 | |||
| 27 | $this->payLoad = json_encode($this->payLoad); |
||
| 28 | $header = $this->getSignHeaders(); |
||
| 29 | $url = $this->getFullUrl(); |
||
| 30 | |||
| 31 | if ($this->getAccessToken()) { |
||
| 32 | $header['Authorization'] = "Bearer " . $this->getAccessToken(); |
||
| 33 | } |
||
| 34 | //Comment out to debug the Request: |
||
| 35 | /* |
||
| 36 | var_dump($url); |
||
| 37 | var_dump($header); |
||
| 38 | var_dump($this->payLoad); |
||
| 39 | */ |
||
| 40 | |||
| 41 | |||
| 42 | switch ($this->getMethod()) { |
||
| 43 | case 'POST': |
||
| 44 | $result = Requests::post($url, $header, $this->payLoad); |
||
| 45 | break; |
||
| 46 | case 'GET': |
||
| 47 | if($this->version == 'v3') |
||
| 48 | { |
||
| 49 | $result = Requests::get($url, $header); |
||
| 50 | } |
||
| 51 | else |
||
| 52 | { |
||
| 53 | $result = Requests::get($url, $header); |
||
| 54 | } |
||
| 55 | break; |
||
| 56 | case 'PUT': |
||
| 57 | $result = Requests::put($url, $header, $this->payLoad); |
||
| 58 | break; |
||
| 59 | } |
||
| 60 | switch ($result->status_code) { |
||
| 61 | case 200: |
||
| 62 | $result = json_decode($result->body, true); |
||
| 63 | break; |
||
| 64 | case 204: |
||
| 65 | $result = "Success"; |
||
| 66 | break; |
||
| 67 | case 401: |
||
| 68 | throw new \Exception('Unauthorized'); |
||
| 69 | break; |
||
| 70 | case 404: |
||
| 71 | //echo "Es wurde bereits gevoted"; |
||
| 72 | case 477: |
||
| 73 | //echo "Es wurde bereits gevoted"; |
||
| 74 | //throw new \Exception('Signing failed!'); |
||
| 75 | break; |
||
| 76 | default: |
||
| 77 | throw new \Exception('Unknown Error: '.$result->status_code); |
||
| 78 | } |
||
| 79 | |||
| 80 | if($device_uid != "") |
||
| 81 | { |
||
| 82 | $result[0] = $result; |
||
| 83 | $result[1] = $device_uid; |
||
| 84 | } |
||
| 85 | |||
| 86 | /* |
||
| 87 | var_dump($result); |
||
| 88 | */ |
||
| 89 | |||
| 90 | return $result; |
||
| 91 | } |
||
| 92 | abstract function getPayload(); |
||
| 158 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.