| Conditions | 14 |
| Paths | 38 |
| Total Lines | 47 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | 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 |
||
| 58 | protected function __setProxyCapabilities($capabilities) |
||
| 59 | { |
||
| 60 | $response = null; |
||
| 61 | |||
| 62 | foreach ($capabilities as $config => $data) { |
||
| 63 | try { |
||
| 64 | if (false === empty($data)) { |
||
| 65 | switch ($config) { |
||
| 66 | case 0: // fix a weird PHP behaviour: when $config === 0 then go in 'blacklist' |
||
| 67 | break; |
||
| 68 | case 'blacklist': |
||
| 69 | $response = $this-_blacklist($data); |
||
| 70 | break; |
||
| 71 | case 'whitelist': |
||
| 72 | $response = $this->_whitelist($data); |
||
|
|
|||
| 73 | break; |
||
| 74 | case 'limits': |
||
| 75 | $response = $this->_limits($data); |
||
| 76 | break; |
||
| 77 | case 'timeouts': |
||
| 78 | $response = $this->_timeouts($data); |
||
| 79 | break; |
||
| 80 | case 'redirect': |
||
| 81 | $response = $this->_remapHosts($data); |
||
| 82 | break; |
||
| 83 | case 'retry': |
||
| 84 | $response = $this->_retry($data); |
||
| 85 | break; |
||
| 86 | case 'basicAuth': |
||
| 87 | $response = $this->_basicAuth($data); |
||
| 88 | break; |
||
| 89 | default: |
||
| 90 | // do nothing |
||
| 91 | } |
||
| 92 | } |
||
| 93 | } catch(\Exception $e) { |
||
| 94 | throw new ModuleConfigException(__CLASS__, $e->getMessage()); |
||
| 95 | } |
||
| 96 | |||
| 97 | if (get_class($response) === 'Request') |
||
| 98 | { |
||
| 99 | if (false === $response->success) { |
||
| 100 | throw new ModuleConfigException(__CLASS__, "Proxy response error '{$reponse->status_code}' {$respone->body}"); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 187 |
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: