| Conditions | 16 |
| Paths | 15 |
| Total Lines | 61 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 45 | public static function callBack(array $request): PBXApiResult |
||
| 46 | { |
||
| 47 | $res = new PBXApiResult(); |
||
| 48 | $res->processor = __METHOD__; |
||
| 49 | |||
| 50 | $action = $request['action']; |
||
| 51 | $data = $request['data']; |
||
| 52 | switch ($action) { |
||
| 53 | case 'getRecord': |
||
| 54 | $res = GetRecord::main($data['id'] ?? ''); |
||
| 55 | break; |
||
| 56 | case 'saveRecord': |
||
| 57 | // Start xdebug session, don't forget to install xdebug.remote_mode = jit on xdebug.ini |
||
| 58 | // and set XDEBUG_SESSION Cookie header on REST request to debug it |
||
| 59 | if (isset($request['debug']) && $request['debug'] === true) { |
||
| 60 | xdebug_break(); |
||
| 61 | } |
||
| 62 | if (!empty($data['number'])) { |
||
| 63 | $res = SaveRecord::main($data); |
||
| 64 | } else { |
||
| 65 | $res->messages['error'][] = 'Empty number value in POST/GET data'; |
||
| 66 | } |
||
| 67 | break; |
||
| 68 | case 'deleteRecord': |
||
| 69 | if (!empty($data['id'])) { |
||
| 70 | $res = DeleteRecord::main($data['id']); |
||
| 71 | } else { |
||
| 72 | $res->messages['error'][] = 'empty ID in POST/GET data'; |
||
| 73 | } |
||
| 74 | break; |
||
| 75 | case 'getForSelect': |
||
| 76 | $res = Dropdowns::getForSelect($data['type'] ?? 'all'); |
||
| 77 | break; |
||
| 78 | case 'available': |
||
| 79 | if (!empty($data['number'])) { |
||
| 80 | $res = Utils::ifNumberAvailable($data['number']); |
||
| 81 | } else { |
||
| 82 | $res->messages['error'][] = 'Empty number value in POST/GET data'; |
||
| 83 | } |
||
| 84 | break; |
||
| 85 | case 'getPhonesRepresent': |
||
| 86 | if (!empty($data['numbers']) || !is_array($data['numbers'])) { |
||
| 87 | $res = Utils::getPhonesRepresent($data['numbers']); |
||
| 88 | } else { |
||
| 89 | $res->messages['error'][] = 'Wrong numbers value in POST/GET data'; |
||
| 90 | } |
||
| 91 | break; |
||
| 92 | case 'getPhoneRepresent': |
||
| 93 | if (!empty($data['number'])) { |
||
| 94 | $res = Utils::getPhoneRepresent($data['number']); |
||
| 95 | } else { |
||
| 96 | $res->messages['error'][] = 'Empty number value in POST/GET data'; |
||
| 97 | } |
||
| 98 | break; |
||
| 99 | default: |
||
| 100 | $res->messages['error'][] = "Unknown action - $action in " . __CLASS__; |
||
| 101 | } |
||
| 102 | |||
| 103 | $res->function = $action; |
||
| 104 | |||
| 105 | return $res; |
||
| 106 | } |
||
| 109 | } |