| Conditions | 1 |
| Total Lines | 79 |
| 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 |
||
| 49 | public function orderInWhichTheEventsHaveBeenRaisedIsPreserved(): void |
||
| 50 | { |
||
| 51 | $event1 = new class implements DomainEvent { |
||
| 52 | public function getName(): string |
||
| 53 | { |
||
| 54 | return 'first'; |
||
| 55 | } |
||
| 56 | }; |
||
| 57 | $event2 = new class implements DomainEvent { |
||
| 58 | public function getName(): string |
||
| 59 | { |
||
| 60 | return 'second'; |
||
| 61 | } |
||
| 62 | }; |
||
| 63 | $event3 = new class implements DomainEvent { |
||
| 64 | public function getName(): string |
||
| 65 | { |
||
| 66 | return 'third'; |
||
| 67 | } |
||
| 68 | }; |
||
| 69 | |||
| 70 | $entity1 = new class implements EventAware{ |
||
| 71 | use OrderedEventRegistry; |
||
| 72 | |||
| 73 | public function trigger(DomainEvent $event): void |
||
| 74 | { |
||
| 75 | $this->triggeredA($event); |
||
| 76 | } |
||
| 77 | }; |
||
| 78 | |||
| 79 | $entity2 = new class implements EventAware { |
||
| 80 | use OrderedEventRegistry; |
||
| 81 | |||
| 82 | public function trigger(DomainEvent $event): void |
||
| 83 | { |
||
| 84 | $this->triggeredA($event); |
||
| 85 | } |
||
| 86 | }; |
||
| 87 | |||
| 88 | $entity1->trigger($event1); |
||
| 89 | $entity2->trigger($event2); |
||
| 90 | $entity1->trigger($event3); |
||
| 91 | |||
| 92 | $uow = $this->createMock(UnitOfWork::class); |
||
| 93 | |||
| 94 | $uow->expects(self::once()) |
||
| 95 | ->method('getScheduledEntityInsertions') |
||
| 96 | ->willReturn([$entity1]); |
||
| 97 | |||
| 98 | $uow->expects(self::once()) |
||
| 99 | ->method('getScheduledEntityUpdates') |
||
| 100 | ->willReturn([$entity2]); |
||
| 101 | |||
| 102 | $uow->expects(self::once()) |
||
| 103 | ->method('getScheduledEntityDeletions') |
||
| 104 | ->willReturn([]); |
||
| 105 | |||
| 106 | $em = $this->createMock(EntityManagerInterface::class); |
||
| 107 | |||
| 108 | $em->expects(self::once())->method('getUnitOfWork')->willReturn($uow); |
||
| 109 | |||
| 110 | $eventArgs = $this->createMock(OnFlushEventArgs::class); |
||
| 111 | $eventArgs->expects(self::once())->method('getEntityManager')->willReturn($em); |
||
| 112 | |||
| 113 | $this->eventDispatcher->/** @scrutinizer ignore-call */expects(self::exactly(3)) |
||
| 114 | ->method('dispatch') |
||
| 115 | ->withConsecutive( |
||
| 116 | [new SymfonyEvent($event1), 'first'], |
||
| 117 | [new SymfonyEvent($event2), 'second'], |
||
| 118 | [new SymfonyEvent($event3), 'third'] |
||
| 119 | ); |
||
| 120 | |||
| 121 | self::assertEquals(3, Counter::getNext()); |
||
| 122 | |||
| 123 | $this->recorder->onFlush($eventArgs); |
||
| 124 | |||
| 125 | self::assertEquals(0, Counter::getNext()); |
||
| 126 | |||
| 127 | $this->doctrineDispatcher->postFlush(); |
||
| 128 | } |
||
| 130 |