| Conditions | 1 |
| Paths | 1 |
| Total Lines | 177 |
| Code Lines | 123 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 131 | public function nodeValuesProvider() { |
||
| 132 | $fieldValues = [ |
||
| 133 | 'body' => [ |
||
| 134 | 'value' => 'test', |
||
| 135 | 'summary' => 'test summary', |
||
| 136 | ], |
||
| 137 | 'field_text' => ['a', 'b', 'c'], |
||
| 138 | 'field_boolean' => [TRUE, FALSE], |
||
| 139 | 'field_link' => [ |
||
| 140 | ['title' => 'Internal link', 'uri' => 'internal:/node/1'], |
||
| 141 | ['title' => 'External link', 'uri' => 'http://drupal.org'], |
||
| 142 | ], |
||
| 143 | 'field_integer' => [10, -5], |
||
| 144 | 'field_float' => [3.14145, -8.8], |
||
| 145 | 'field_decimal' => [10.5, -17.22], |
||
| 146 | 'field_datetime' => ['2017-01-01', '1900-01-01'], |
||
| 147 | 'field_timestamp' => [0, 300], |
||
| 148 | 'field_email' => ['[email protected]'], |
||
| 149 | 'field_string' => ['test', '123'], |
||
| 150 | 'field_reference' => [ |
||
| 151 | ['target_id' => 1], |
||
| 152 | ], |
||
| 153 | 'field_file' => [ |
||
| 154 | [ |
||
| 155 | 'target_id' => 1, |
||
| 156 | 'display' => 0, |
||
| 157 | 'description' => 'description test 1', |
||
| 158 | ], |
||
| 159 | [ |
||
| 160 | 'target_id' => 2, |
||
| 161 | 'display' => 1, |
||
| 162 | 'description' => 'description test 2', |
||
| 163 | ], |
||
| 164 | ], |
||
| 165 | 'field_image' => [ |
||
| 166 | [ |
||
| 167 | 'target_id' => 1, |
||
| 168 | 'alt' => 'alt test 1', |
||
| 169 | 'title' => 'title test 1', |
||
| 170 | 'width' => 100, |
||
| 171 | 'height' => 50, |
||
| 172 | ], |
||
| 173 | [ |
||
| 174 | 'target_id' => 2, |
||
| 175 | 'alt' => 'alt test 2', |
||
| 176 | 'title' => 'title test 2', |
||
| 177 | 'width' => 200, |
||
| 178 | 'height' => 100, |
||
| 179 | ], |
||
| 180 | ], |
||
| 181 | ]; |
||
| 182 | |||
| 183 | $expected = [ |
||
| 184 | 'nid' => 1, |
||
| 185 | 'vid' => 1, |
||
| 186 | 'langcode' => [ |
||
| 187 | 'value' => 'en', |
||
| 188 | ], |
||
| 189 | 'type' => [ |
||
| 190 | 'targetId' => 'test', |
||
| 191 | ], |
||
| 192 | 'uid' => [ |
||
| 193 | 'targetId' => 0, |
||
| 194 | 'entity' => NULL, |
||
| 195 | ], |
||
| 196 | 'title' => 'Test', |
||
| 197 | 'status' => 1, |
||
| 198 | 'promote' => 1, |
||
| 199 | 'sticky' => 0, |
||
| 200 | 'revisionTranslationAffected' => 1, |
||
| 201 | 'body' => [ |
||
| 202 | 'value' => 'test', |
||
| 203 | 'summary' => 'test summary', |
||
| 204 | 'summaryProcessed' => "<p>test summary</p>\n", |
||
| 205 | 'processed' => "<p>test</p>\n", |
||
| 206 | 'format' => NULL, |
||
| 207 | ], |
||
| 208 | 'fieldText' => [ |
||
| 209 | ['value' => 'a'], |
||
| 210 | ['value' => 'b'], |
||
| 211 | ['value' => 'c'], |
||
| 212 | ], |
||
| 213 | 'fieldBoolean' => [ |
||
| 214 | TRUE, |
||
| 215 | FALSE, |
||
| 216 | ], |
||
| 217 | 'fieldLink' => [ |
||
| 218 | ['title' => 'Internal link', 'uri' => 'internal:/node/1'], |
||
| 219 | ['title' => 'External link', 'uri' => 'http://drupal.org'], |
||
| 220 | ], |
||
| 221 | 'fieldInteger' => [ |
||
| 222 | 10, |
||
| 223 | -5, |
||
| 224 | ], |
||
| 225 | 'fieldFloat' => [ |
||
| 226 | 3.14145, |
||
| 227 | -8.8, |
||
| 228 | ], |
||
| 229 | 'fieldDecimal' => [ |
||
| 230 | 10.5, |
||
| 231 | -17.22, |
||
| 232 | ], |
||
| 233 | 'fieldDatetime' => [ |
||
| 234 | ['value' => '2017-01-01'], |
||
| 235 | ['value' => '1900-01-01'], |
||
| 236 | ], |
||
| 237 | 'fieldTimestamp' => [ |
||
| 238 | 0, |
||
| 239 | 300, |
||
| 240 | ], |
||
| 241 | 'fieldEmail' => ['[email protected]'], |
||
| 242 | 'fieldString' => [ |
||
| 243 | 'test', |
||
| 244 | '123', |
||
| 245 | ], |
||
| 246 | 'fieldReference' => [ |
||
| 247 | [ |
||
| 248 | 'targetId' => 1, |
||
| 249 | 'entity' => [ |
||
| 250 | 'title' => 'Test', |
||
| 251 | 'fieldReference' => [ |
||
| 252 | [ |
||
| 253 | 'targetId' => 1, |
||
| 254 | 'entity' => [ |
||
| 255 | 'title' => 'Test', |
||
| 256 | ], |
||
| 257 | ], |
||
| 258 | ], |
||
| 259 | ], |
||
| 260 | ], |
||
| 261 | ], |
||
| 262 | 'fieldFile' => [ |
||
| 263 | [ |
||
| 264 | 'targetId' => 1, |
||
| 265 | 'display' => 0, |
||
| 266 | 'description' => 'description test 1', |
||
| 267 | 'entity' => [ |
||
| 268 | 'uri' => 'public://example.txt' |
||
| 269 | ], |
||
| 270 | ], |
||
| 271 | [ |
||
| 272 | 'targetId' => 2, |
||
| 273 | 'display' => 1, |
||
| 274 | 'description' => 'description test 2', |
||
| 275 | 'entity' => [ |
||
| 276 | 'uri' => 'public://example.png' |
||
| 277 | ], |
||
| 278 | ], |
||
| 279 | ], |
||
| 280 | 'fieldImage' => [ |
||
| 281 | [ |
||
| 282 | 'targetId' => 1, |
||
| 283 | 'alt' => 'alt test 1', |
||
| 284 | 'title' => 'title test 1', |
||
| 285 | 'width' => 100, |
||
| 286 | 'height' => 50, |
||
| 287 | 'entity' => [ |
||
| 288 | 'uri' => 'public://example.txt' |
||
| 289 | ], |
||
| 290 | ], |
||
| 291 | [ |
||
| 292 | 'targetId' => 2, |
||
| 293 | 'alt' => 'alt test 2', |
||
| 294 | 'title' => 'title test 2', |
||
| 295 | 'width' => 200, |
||
| 296 | 'height' => 100, |
||
| 297 | 'entity' => [ |
||
| 298 | 'uri' => 'public://example.png' |
||
| 299 | ], |
||
| 300 | ], |
||
| 301 | ], |
||
| 302 | ]; |
||
| 303 | |||
| 304 | return [ |
||
| 305 | [$fieldValues, $expected], |
||
| 306 | ]; |
||
| 307 | } |
||
| 308 | |||
| 335 |