Conditions | 12 |
Paths | 20 |
Total Lines | 33 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
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 |
||
31 | public function __invoke($attribute, $value, $fail): void |
||
32 | { |
||
33 | $causationFieldValue = data_get($this->data, $this->conditional['field']); |
||
34 | |||
35 | // $causationFieldValue is an array? always? |
||
36 | |||
37 | $condition = $this->conditional['condition']; |
||
38 | $operator = $this->conditional['operator']; |
||
39 | |||
40 | $fieldIsRequired = false; |
||
41 | |||
42 | if ($operator === '>') { |
||
43 | $fieldIsRequired = $causationFieldValue > $condition; |
||
44 | } else if ($operator === '<') { |
||
45 | $fieldIsRequired = $causationFieldValue < $condition; |
||
46 | } else if ($operator === '==') { |
||
47 | $fieldIsRequired = $causationFieldValue == $condition; |
||
48 | } else if ($operator === '===') { |
||
49 | $fieldIsRequired = $causationFieldValue === $condition; |
||
50 | } else if ($operator === '!=') { |
||
51 | $fieldIsRequired = $causationFieldValue != $condition; |
||
52 | } else if ($operator === '!==') { |
||
53 | $fieldIsRequired = $causationFieldValue !== $condition; |
||
54 | } else if ($operator === '>=') { |
||
55 | $fieldIsRequired = $causationFieldValue >= $condition; |
||
56 | } else if ($operator === '<=') { |
||
57 | $fieldIsRequired = $causationFieldValue <= $condition; |
||
58 | } else if ($operator === 'one_of') { |
||
59 | $fieldIsRequired = in_array((int) $causationFieldValue[0], $condition); // always array? |
||
60 | } |
||
61 | |||
62 | if ($fieldIsRequired && !$value) { |
||
63 | $fail('This field is required.'); |
||
64 | } |
||
90 |