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