Total Lines | 156 |
Code Lines | 49 |
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 declare(strict_types=1); |
||
249 | private function getFixtureModifier(): FixtureEntitiesModifierInterface |
||
250 | { |
||
251 | |||
252 | return new class( |
||
253 | $this->getCopiedFqn(self::ENTITY_WITH_MODIFIER), |
||
254 | $this->getEntityFactory(), |
||
255 | $this->getEntityDtoFactory(), |
||
256 | $this->getUuidFactory(), |
||
257 | $this->getCopiedFqn(self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_EMAIL) |
||
258 | ) |
||
259 | implements FixtureEntitiesModifierInterface |
||
260 | { |
||
261 | /** |
||
262 | * @var string |
||
263 | */ |
||
264 | protected $entityFqn; |
||
265 | /** |
||
266 | * @var EntityFactoryInterface |
||
267 | */ |
||
268 | protected $factory; |
||
269 | /** |
||
270 | * @var array|EntityInterface[] |
||
271 | */ |
||
272 | private $entities; |
||
273 | /** |
||
274 | * @var DtoFactory |
||
275 | */ |
||
276 | private $dtoFactory; |
||
277 | /** |
||
278 | * @var UuidFactory |
||
279 | */ |
||
280 | private $uuidFactory; |
||
281 | /** |
||
282 | * @var string |
||
283 | */ |
||
284 | private $emailFqn; |
||
285 | |||
286 | public function __construct( |
||
287 | string $entityFqn, |
||
288 | EntityFactoryInterface $factory, |
||
289 | DtoFactory $dtoFactory, |
||
290 | UuidFactory $uuidFactory, |
||
291 | string $emailFqn |
||
292 | ) { |
||
293 | $this->entityFqn = $entityFqn; |
||
294 | $this->factory = $factory; |
||
295 | $this->dtoFactory = $dtoFactory; |
||
296 | $this->uuidFactory = $uuidFactory; |
||
297 | $this->emailFqn = $emailFqn; |
||
298 | } |
||
299 | |||
300 | /** |
||
301 | * Update the entities array by reference |
||
302 | * |
||
303 | * @param array $entities |
||
304 | */ |
||
305 | public function modifyEntities(array &$entities): void |
||
306 | { |
||
307 | $this->entities = &$entities; |
||
308 | $this->updateFirstEntity(); |
||
309 | $this->addAnotherEntity(); |
||
310 | } |
||
311 | |||
312 | private function updateFirstEntity(): void |
||
313 | { |
||
314 | $firstEntity = current($this->entities); |
||
315 | $firstEntity->update( |
||
316 | new class($this->entityFqn, $firstEntity->getId()) |
||
317 | implements DataTransferObjectInterface |
||
318 | { |
||
319 | /** |
||
320 | * @var string |
||
321 | */ |
||
322 | private static $entityFqn; |
||
323 | /** |
||
324 | * @var UuidInterface |
||
325 | */ |
||
326 | private $id; |
||
327 | |||
328 | public function __construct(string $entityFqn, UuidInterface $id) |
||
329 | { |
||
330 | self::$entityFqn = $entityFqn; |
||
331 | $this->id = $id; |
||
332 | } |
||
333 | |||
334 | public function getString(): string |
||
335 | { |
||
336 | return 'This has been overridden'; |
||
337 | } |
||
338 | |||
339 | public static function getEntityFqn(): string |
||
340 | { |
||
341 | return self::$entityFqn; |
||
342 | } |
||
343 | |||
344 | public function getId(): UuidInterface |
||
345 | { |
||
346 | return $this->id; |
||
347 | } |
||
348 | } |
||
349 | ); |
||
350 | } |
||
351 | |||
352 | private function addAnotherEntity(): void |
||
353 | { |
||
354 | $address = $this->factory->create($this->emailFqn); |
||
355 | $entity = $this->factory->create( |
||
356 | $this->entityFqn, |
||
357 | new class($this->entityFqn, $this->uuidFactory, $address) implements DataTransferObjectInterface |
||
358 | { |
||
359 | /** |
||
360 | * @var string |
||
361 | */ |
||
362 | private static $entityFqn; |
||
363 | /** |
||
364 | * @var UuidInterface |
||
365 | */ |
||
366 | private $id; |
||
367 | /** |
||
368 | * @var EntityInterface |
||
369 | */ |
||
370 | private $email; |
||
371 | |||
372 | public function __construct(string $entityFqn, UuidFactory $factory, EntityInterface $email) |
||
373 | { |
||
374 | self::$entityFqn = $entityFqn; |
||
375 | $this->id = $factory->getOrderedTimeUuid(); |
||
376 | $this->email = $email; |
||
377 | } |
||
378 | |||
379 | public function getString(): string |
||
380 | { |
||
381 | return 'This has been created'; |
||
382 | } |
||
383 | |||
384 | public static function getEntityFqn(): string |
||
385 | { |
||
386 | return self::$entityFqn; |
||
387 | } |
||
388 | |||
389 | public function getId(): UuidInterface |
||
390 | { |
||
391 | return $this->id; |
||
392 | } |
||
393 | |||
394 | public function getAttributesEmails(): ArrayCollection |
||
395 | { |
||
396 | $collection = new ArrayCollection(); |
||
397 | $collection->add($this->email); |
||
398 | |||
399 | return $collection; |
||
400 | } |
||
401 | } |
||
402 | ); |
||
403 | |||
404 | $this->entities[] = $entity; |
||
405 | } |
||
409 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.