Conditions | 2 |
Total Lines | 54 |
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 |
||
134 | private function getEventArgs(bool $withEvents = true) : OnFlushEventArgs |
||
135 | { |
||
136 | $insertions = $updates = $deletions = []; |
||
137 | |||
138 | if ($withEvents) { |
||
139 | $entity1 = new class() implements EventAware { |
||
140 | use OrderedEventRegistry; |
||
141 | |||
142 | public function trigger(DomainEvent $event) : void |
||
143 | { |
||
144 | $this->triggeredA($event); |
||
145 | } |
||
146 | }; |
||
147 | |||
148 | $entity2 = new class() implements EventAware { |
||
149 | use OrderedEventRegistry; |
||
150 | |||
151 | public function trigger(DomainEvent $event) : void |
||
152 | { |
||
153 | $this->triggeredA($event); |
||
154 | } |
||
155 | }; |
||
156 | |||
157 | $entity3 = new class() implements EventAware { |
||
158 | use OrderedEventRegistry; |
||
159 | |||
160 | public function trigger(DomainEvent $event) : void |
||
161 | { |
||
162 | $this->triggeredA($event); |
||
163 | } |
||
164 | }; |
||
165 | |||
166 | $domainEvent1 = new FirstDomainEvent(); |
||
167 | $domainEvent2 = new SecondDomainEvent(); |
||
168 | $domainEvent3 = new ThirdDomainEvent(); |
||
169 | |||
170 | $entity1->trigger($domainEvent1); |
||
171 | $entity2->trigger($domainEvent2); |
||
172 | $entity3->trigger($domainEvent3); |
||
173 | |||
174 | $updates = [$entity3]; |
||
175 | $deletions = [$entity2, $entity1]; |
||
176 | } |
||
177 | |||
178 | $this->unitOfWork->expects(self::once())->method('getScheduledEntityInsertions')->willReturn($insertions); |
||
179 | $this->unitOfWork->expects(self::once())->method('getScheduledEntityUpdates')->willReturn($updates); |
||
180 | $this->unitOfWork->expects(self::once())->method('getScheduledEntityDeletions')->willReturn($deletions); |
||
181 | |||
182 | $this->entityManager->expects(self::any())->method('getUnitOfWork')->willReturn($this->unitOfWork); |
||
183 | |||
184 | $eventArgs = $this->createMock(OnFlushEventArgs::class); |
||
185 | $eventArgs->expects(self::any())->method('getEntityManager')->willReturn($this->entityManager); |
||
186 | |||
187 | return $eventArgs; |
||
|
|||
188 | } |
||
190 |