| Conditions | 12 |
| Paths | 12 |
| Total Lines | 27 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 77 | protected function getFlag() |
||
| 78 | { |
||
| 79 | switch ($this->version) { |
||
| 80 | case static::V4: |
||
| 81 | return FILTER_FLAG_IPV4; |
||
| 82 | case static::V6: |
||
| 83 | return FILTER_FLAG_IPV6; |
||
| 84 | case static::V4_NO_PRIV: |
||
| 85 | return FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE; |
||
| 86 | case static::V6_NO_PRIV: |
||
| 87 | return FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE; |
||
| 88 | case static::ALL_NO_PRIV: |
||
| 89 | return FILTER_FLAG_NO_PRIV_RANGE; |
||
| 90 | case static::V4_NO_RES: |
||
| 91 | return FILTER_FLAG_IPV4 | FILTER_FLAG_NO_RES_RANGE; |
||
| 92 | case static::V6_NO_RES: |
||
| 93 | return FILTER_FLAG_IPV6 | FILTER_FLAG_NO_RES_RANGE; |
||
| 94 | case static::ALL_NO_RES: |
||
| 95 | return FILTER_FLAG_NO_RES_RANGE; |
||
| 96 | case static::V4_ONLY_PUBLIC: |
||
| 97 | return FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE; |
||
| 98 | case static::V6_ONLY_PUBLIC: |
||
| 99 | return FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE; |
||
| 100 | case static::ALL_ONLY_PUBLIC: |
||
| 101 | return FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE; |
||
| 102 | default: |
||
| 103 | return null; |
||
| 104 | } |
||
| 107 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.