| Conditions | 12 |
| Paths | 14 |
| Total Lines | 30 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 46 | public function __set($option, $value) |
||
| 47 | { |
||
| 48 | switch ($option) { |
||
| 49 | case CartItem::ITEM_QTY: |
||
| 50 | if (!is_numeric($value) || $value < 0) { |
||
| 51 | throw new InvalidQuantity('The quantity must be a valid number'); |
||
| 52 | } |
||
| 53 | break; |
||
| 54 | case CartItem::ITEM_PRICE: |
||
| 55 | if (!is_numeric($value)) { |
||
| 56 | throw new InvalidPrice('The price must be a valid number'); |
||
| 57 | } |
||
| 58 | break; |
||
| 59 | case CartItem::ITEM_TAX: |
||
| 60 | if (!is_numeric($value) || $value > 1) { |
||
| 61 | throw new InvalidTaxableValue('The tax must be a float less than 1'); |
||
| 62 | } |
||
| 63 | break; |
||
| 64 | case CartItem::ITEM_TAXABLE: |
||
| 65 | if(!is_bool($value)) { |
||
| 66 | throw new InvalidTaxableValue('The taxable option must be a boolean'); |
||
| 67 | } |
||
| 68 | break; |
||
| 69 | } |
||
| 70 | array_set($this->options, $option, $value); |
||
| 71 | |||
| 72 | if (is_callable(array($this, 'generateHash'))) { |
||
| 73 | $this->generateHash(); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 93 |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return,dieorexitstatements that have been added for debug purposes.In the above example, the last
return falsewill never be executed, because a return statement has already been met in every possible execution path.