Conditions | 11 |
Paths | 5 |
Total Lines | 19 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 namespace Limoncello\Validation\Rules\Converters; |
||
49 | public static function execute($value, ContextInterface $context): array |
||
50 | { |
||
51 | if (is_string($value) === true) { |
||
52 | $lcValue = strtolower($value); |
||
53 | if ($lcValue === 'true' || $lcValue === '1' || $lcValue === 'on' || $lcValue === 'yes') { |
||
54 | $reply = BlockReplies::createSuccessReply(true); |
||
55 | } elseif ($lcValue === 'false' || $lcValue === '0' || $lcValue === 'off' || $lcValue === 'no') { |
||
56 | $reply = BlockReplies::createSuccessReply(false); |
||
57 | } else { |
||
58 | $reply = BlockReplies::createErrorReply($context, $value, ErrorCodes::IS_BOOL); |
||
59 | } |
||
60 | } elseif (is_bool($value) === true) { |
||
61 | $reply = BlockReplies::createSuccessReply($value); |
||
62 | } else { |
||
63 | $reply = BlockReplies::createErrorReply($context, $value, ErrorCodes::IS_BOOL); |
||
64 | } |
||
65 | |||
66 | return $reply; |
||
67 | } |
||
68 | } |
||
69 |