| Conditions | 13 |
| Paths | 13 |
| Total Lines | 31 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 48 | public function __call($method, $arguments) |
||
| 49 | { |
||
| 50 | $var = lcfirst(substr($method, 3)); |
||
| 51 | $underscored = $this->underscore($var); |
||
| 52 | |||
| 53 | if (strncasecmp($method, 'get', 3) == 0) { |
||
| 54 | if ($this->has($var) && property_exists($this, $var)) { |
||
| 55 | return $this->$var; |
||
| 56 | } elseif ($this->has($underscored) && property_exists($this, $underscored)) { |
||
| 57 | return $this->$underscored; |
||
| 58 | } elseif ($this->has($var)) { |
||
| 59 | return $this->_fields[$var]; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | |||
| 63 | if (strncasecmp($method, 'serialize', 9) == 0) { |
||
| 64 | $method = 'get' . substr($method, 9); |
||
| 65 | |||
| 66 | return $this->$method(); |
||
| 67 | } |
||
| 68 | |||
| 69 | if (strncasecmp($method, 'set', 3) == 0) { |
||
| 70 | if ($this->has($var) && property_exists($this, $var)) { |
||
| 71 | $this->$var = $arguments[0]; |
||
| 72 | } elseif ($this->has($underscored) && property_exists($this, $underscored)) { |
||
| 73 | $this->$underscored = $arguments[0]; |
||
| 74 | } else { |
||
| 75 | $this->_fields[$var] = $arguments[0]; |
||
| 76 | } |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 139 |