| Conditions | 1 |
| Paths | 1 |
| Total Lines | 77 |
| Code Lines | 56 |
| 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 |
||
| 27 | public function dataOptions(): array |
||
| 28 | { |
||
| 29 | return [ |
||
| 30 | [ |
||
| 31 | new LessThan(1), |
||
| 32 | [ |
||
| 33 | 'targetValue' => 1, |
||
| 34 | 'targetAttribute' => null, |
||
| 35 | 'incorrectInputMessage' => [ |
||
| 36 | 'template' => 'The allowed types are integer, float, string, boolean, null and object ' . |
||
| 37 | 'implementing \Stringable interface or \DateTimeInterface.', |
||
| 38 | 'parameters' => [ |
||
| 39 | 'targetValue' => 1, |
||
| 40 | 'targetAttribute' => null, |
||
| 41 | 'targetValueOrAttribute' => 1, |
||
| 42 | ], |
||
| 43 | ], |
||
| 44 | 'incorrectDataSetTypeMessage' => [ |
||
| 45 | 'template' => 'The attribute value returned from a custom data set must have one of the ' . |
||
| 46 | 'following types: integer, float, string, boolean, null or an object implementing ' . |
||
| 47 | '\Stringable interface or \DateTimeInterface.', |
||
| 48 | 'parameters' => [ |
||
| 49 | 'targetValue' => 1, |
||
| 50 | 'targetAttribute' => null, |
||
| 51 | 'targetValueOrAttribute' => 1, |
||
| 52 | ], |
||
| 53 | ], |
||
| 54 | 'message' => [ |
||
| 55 | 'template' => 'Value must be less than "{targetValueOrAttribute}".', |
||
| 56 | 'parameters' => [ |
||
| 57 | 'targetValue' => 1, |
||
| 58 | 'targetAttribute' => null, |
||
| 59 | 'targetValueOrAttribute' => 1, |
||
| 60 | ], |
||
| 61 | ], |
||
| 62 | 'type' => 'number', |
||
| 63 | 'operator' => '<', |
||
| 64 | 'skipOnEmpty' => false, |
||
| 65 | 'skipOnError' => false, |
||
| 66 | ], |
||
| 67 | ], |
||
| 68 | [ |
||
| 69 | new LessThan( |
||
| 70 | new DateTime('2023-02-07 12:57:12'), |
||
| 71 | targetAttribute: 'test', |
||
| 72 | incorrectInputMessage: 'Custom message 1.', |
||
| 73 | incorrectDataSetTypeMessage: 'Custom message 2.', |
||
| 74 | message: 'Custom message 3.', |
||
| 75 | type: CompareType::ORIGINAL, |
||
| 76 | skipOnEmpty: true, |
||
| 77 | skipOnError: true, |
||
| 78 | when: static fn (): bool => true, |
||
| 79 | ), |
||
| 80 | [ |
||
| 81 | 'targetAttribute' => 'test', |
||
| 82 | 'incorrectInputMessage' => [ |
||
| 83 | 'template' => 'Custom message 1.', |
||
| 84 | 'parameters' => [ |
||
| 85 | 'targetAttribute' => 'test', |
||
| 86 | ], |
||
| 87 | ], |
||
| 88 | 'incorrectDataSetTypeMessage' => [ |
||
| 89 | 'template' => 'Custom message 2.', |
||
| 90 | 'parameters' => [ |
||
| 91 | 'targetAttribute' => 'test', |
||
| 92 | ], |
||
| 93 | ], |
||
| 94 | 'message' => [ |
||
| 95 | 'template' => 'Custom message 3.', |
||
| 96 | 'parameters' => [ |
||
| 97 | 'targetAttribute' => 'test', |
||
| 98 | ], |
||
| 99 | ], |
||
| 100 | 'type' => 'original', |
||
| 101 | 'operator' => '<', |
||
| 102 | 'skipOnEmpty' => true, |
||
| 103 | 'skipOnError' => true, |
||
| 104 | ], |
||
| 139 |