| Total Lines | 82 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 107 | public function dataValidationPassed(): array |
||
| 108 | { |
||
| 109 | return [ |
||
| 110 | [ |
||
| 111 | new class () { |
||
| 112 | public $attr1 = 1; |
||
| 113 | public $attr2 = null; |
||
| 114 | }, |
||
| 115 | [new AtLeast(['attr1', 'attr2'])], |
||
| 116 | ], |
||
| 117 | [ |
||
| 118 | new class () { |
||
| 119 | public $attr1 = null; |
||
| 120 | public $attr2 = 1; |
||
| 121 | }, |
||
| 122 | [new AtLeast(['attr2'])], |
||
| 123 | ], |
||
| 124 | [ |
||
| 125 | new class () { |
||
| 126 | private int $attr1 = 1; |
||
|
|
|||
| 127 | private $attr2 = null; |
||
| 128 | }, |
||
| 129 | [new AtLeast(['attr1', 'attr2'])], |
||
| 130 | ], |
||
| 131 | [ |
||
| 132 | ['attr1' => 1, 'attr2' => null], |
||
| 133 | [new AtLeast(['attr1', 'attr2'])], |
||
| 134 | ], |
||
| 135 | [ |
||
| 136 | ['attr1' => null, 'attr2' => 1], |
||
| 137 | [new AtLeast(['attr2'])], |
||
| 138 | ], |
||
| 139 | [ |
||
| 140 | new class () { |
||
| 141 | public $obj; |
||
| 142 | |||
| 143 | public function __construct() |
||
| 144 | { |
||
| 145 | $this->obj = new class () { |
||
| 146 | public $attr1 = 1; |
||
| 147 | public $attr2 = null; |
||
| 148 | }; |
||
| 149 | } |
||
| 150 | }, |
||
| 151 | ['obj' => new AtLeast(['attr1', 'attr2'])], |
||
| 152 | ], |
||
| 153 | [ |
||
| 154 | new class () { |
||
| 155 | public $obj; |
||
| 156 | |||
| 157 | public function __construct() |
||
| 158 | { |
||
| 159 | $this->obj = new class () { |
||
| 160 | public $attr1 = null; |
||
| 161 | public $attr2 = 1; |
||
| 162 | }; |
||
| 163 | } |
||
| 164 | }, |
||
| 165 | ['obj' => new AtLeast(['attr2'])], |
||
| 166 | ], |
||
| 167 | [ |
||
| 168 | ['obj' => ['attr1' => 1, 'attr2' => null]], |
||
| 169 | ['obj' => new AtLeast(['attr1', 'attr2'])], |
||
| 170 | ], |
||
| 171 | [ |
||
| 172 | ['obj' => ['attr1' => null, 'attr2' => 1]], |
||
| 173 | ['obj' => new AtLeast(['attr2'])], |
||
| 174 | ], |
||
| 175 | 'more than "min" attributes are filled' => [ |
||
| 176 | ['attr1' => 1, 'attr2' => 2], |
||
| 177 | [new AtLeast(['attr1', 'attr2'])], |
||
| 178 | ], |
||
| 179 | 'min equals amount of attributes' => [ |
||
| 180 | ['attr1' => 1, 'attr2' => 2], |
||
| 181 | [new AtLeast(['attr1', 'attr2'], min: 2)], |
||
| 182 | ], |
||
| 183 | 'min equals amount of attributes, 0' => [ |
||
| 184 | [], |
||
| 185 | [new AtLeast([], min: 0)], |
||
| 186 | ], |
||
| 187 | 'class attribute' => [ |
||
| 188 | new AtLeastDto(1), |
||
| 189 | ], |
||
| 286 |