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