| Conditions | 10 |
| Paths | 7 |
| Total Lines | 29 |
| Code Lines | 18 |
| 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 |
||
| 69 | public function requestedWith($type = null) |
||
| 70 | { |
||
| 71 | $request = $this->request; |
||
| 72 | if (!$request->is('post') && |
||
| 73 | !$request->is('put') && |
||
| 74 | !$request->is('patch') && |
||
| 75 | !$request->is('delete') |
||
| 76 | ) { |
||
| 77 | return null; |
||
| 78 | } |
||
| 79 | if (is_array($type)) { |
||
| 80 | foreach ($type as $t) { |
||
| 81 | if ($this->requestedWith($t)) { |
||
| 82 | return $t; |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | return false; |
||
| 87 | } |
||
| 88 | |||
| 89 | list($contentType) = explode(';', $request->contentType()); |
||
| 90 | $response = $this->response; |
||
| 91 | if ($type === null) { |
||
| 92 | return $response->mapType($contentType); |
||
| 93 | } |
||
| 94 | if (is_string($type)) { |
||
| 95 | return ($type === $response->mapType($contentType)); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 122 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: