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 |
||
27 | private function getEventArgs(bool $withEvents = true) : OnFlushEventArgs |
||
28 | { |
||
29 | $insertions = $updates = $deletions = []; |
||
30 | |||
31 | if ($withEvents) { |
||
32 | $entity1 = new class() implements EventAware { |
||
33 | use OrderedEventRegistry; |
||
34 | |||
35 | public function trigger(DomainEvent $event) : void |
||
36 | { |
||
37 | $this->triggeredA($event); |
||
38 | } |
||
39 | }; |
||
40 | |||
41 | $entity2 = new class() implements EventAware { |
||
42 | use OrderedEventRegistry; |
||
43 | |||
44 | public function trigger(DomainEvent $event) : void |
||
45 | { |
||
46 | $this->triggeredA($event); |
||
47 | } |
||
48 | }; |
||
49 | |||
50 | $entity3 = new class() implements EventAware { |
||
51 | use OrderedEventRegistry; |
||
52 | |||
53 | public function trigger(DomainEvent $event) : void |
||
54 | { |
||
55 | $this->triggeredA($event); |
||
56 | } |
||
57 | }; |
||
58 | |||
59 | $domainEvent1 = new FirstDomainEvent(); |
||
60 | $domainEvent2 = new SecondDomainEvent(); |
||
61 | $domainEvent3 = new ThirdDomainEvent(); |
||
62 | |||
63 | $entity1->trigger($domainEvent1); |
||
64 | $entity2->trigger($domainEvent2); |
||
65 | $entity3->trigger($domainEvent3); |
||
66 | |||
67 | $updates = [$entity3]; |
||
68 | $deletions = [$entity2, $entity1]; |
||
69 | } |
||
70 | |||
71 | $this->unitOfWork->expects(self::any())->method('getScheduledEntityInsertions')->willReturn($insertions); |
||
72 | $this->unitOfWork->expects(self::any())->method('getScheduledEntityUpdates')->willReturn($updates); |
||
73 | $this->unitOfWork->expects(self::any())->method('getScheduledEntityDeletions')->willReturn($deletions); |
||
74 | |||
75 | $this->entityManager->expects(self::any())->method('getUnitOfWork')->willReturn($this->unitOfWork); |
||
76 | |||
77 | $eventArgs = $this->createMock(OnFlushEventArgs::class); |
||
|
|||
78 | $eventArgs->expects(self::any())->method('getEntityManager')->willReturn($this->entityManager); |
||
79 | |||
80 | return $eventArgs; |
||
81 | } |
||
83 |