| Conditions | 10 |
| Paths | 26 |
| Total Lines | 28 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 18 |
| CRAP Score | 11.0275 |
| Changes | 3 | ||
| 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 |
||
| 43 | 75 | protected function _cast($value, $string = false) |
|
| 44 | { |
||
| 45 | 75 | if (!$value instanceof MongoId) |
|
| 46 | 75 | { |
|
| 47 | 73 | if (is_array($value) && isset($value['$id'])) |
|
| 48 | 73 | { |
|
| 49 | $value = $value['$id']; |
||
| 50 | } |
||
| 51 | 73 | if (is_object($value) && isset($value->{'$id'})) |
|
| 52 | 73 | { |
|
| 53 | $value = $value->{'$id'}; |
||
| 54 | } |
||
| 55 | 73 | if (!preg_match('~^[a-z0-9]{24}$~', $value)) |
|
| 56 | 62 | { |
|
| 57 | 60 | $value = null; |
|
| 58 | 60 | } |
|
| 59 | 62 | if ($this->nullable && empty($value)) |
|
| 60 | 62 | { |
|
| 61 | return null; |
||
| 62 | } |
||
| 63 | 62 | $value = new MongoId($value); |
|
| 64 | 62 | } |
|
| 65 | if ($string) |
||
| 66 | 71 | { |
|
| 67 | 1 | return (string) $value; |
|
| 68 | } |
||
| 69 | 71 | return $value; |
|
| 70 | } |
||
| 71 | |||
| 73 |