Conditions | 15 |
Paths | 46 |
Total Lines | 41 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 11 | ||
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'])[0]; |
||
34 | $causationFieldValue = data_get($this->data, $this->conditional['field']); |
||
35 | |||
36 | if (is_array($causationFieldValue)) { |
||
37 | $causationFieldValue = $causationFieldValue[0]; |
||
38 | } |
||
39 | |||
40 | // $causationFieldValue is an array? always? |
||
41 | |||
42 | $condition = $this->conditional['condition']; |
||
43 | $operator = $this->conditional['operator']; |
||
44 | |||
45 | $fieldIsRequired = false; |
||
46 | |||
47 | if (!is_null($causationFieldValue)) { |
||
48 | 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 === '!==') { |
||
59 | $fieldIsRequired = $causationFieldValue !== $condition; |
||
60 | } else if ($operator === '>=') { |
||
61 | $fieldIsRequired = $causationFieldValue >= $condition; |
||
62 | } else if ($operator === '<=') { |
||
63 | $fieldIsRequired = $causationFieldValue <= $condition; |
||
64 | } else if ($operator === 'one_of') { |
||
65 | $fieldIsRequired = in_array((int) $causationFieldValue, $condition); // always array? |
||
66 | } else if ($operator === 'not_one_of') { |
||
67 | $fieldIsRequired = !in_array((int) $causationFieldValue, $condition); // always array? |
||
68 | } |
||
69 | |||
70 | if ($fieldIsRequired && !$value) { |
||
71 | $fail('This field is required'); |
||
72 | } |
||
99 |
This interface has been deprecated. The supplier of the interface has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.