Conditions | 3 |
Paths | 4 |
Total Lines | 233 |
Code Lines | 120 |
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 static function createSerializer(ReadRepositoryInterface $labelRepository) |
||
54 | { |
||
55 | $payloadManipulatingSerializer = new PayloadManipulatingSerializer( |
||
56 | new SimpleInterfaceSerializer() |
||
57 | ); |
||
58 | |||
59 | /* |
||
60 | * CREATE EVENTS |
||
61 | * |
||
62 | */ |
||
63 | |||
64 | $payloadManipulatingSerializer->manipulateEventsOfClass( |
||
65 | 'CultuurNet\UDB3\Event\Events\EventCreated', |
||
66 | function (array $serializedObject) { |
||
67 | return self::addDefaultMainLanguage($serializedObject); |
||
68 | } |
||
69 | ); |
||
70 | |||
71 | $payloadManipulatingSerializer->manipulateEventsOfClass( |
||
72 | 'CultuurNet\UDB3\Place\Events\PlaceCreated', |
||
73 | function (array $serializedObject) { |
||
74 | return self::addDefaultMainLanguage($serializedObject); |
||
75 | } |
||
76 | ); |
||
77 | |||
78 | /* |
||
79 | * TRANSLATION EVENTS |
||
80 | */ |
||
81 | |||
82 | $payloadManipulatingSerializer->manipulateEventsOfClass( |
||
83 | 'CultuurNet\UDB3\Event\TitleTranslated', |
||
84 | function (array $serializedObject) { |
||
85 | $serializedObject['class'] = TitleTranslated::class; |
||
86 | |||
87 | $serializedObject = self::replaceEventIdWithItemId($serializedObject); |
||
88 | |||
89 | return $serializedObject; |
||
90 | } |
||
91 | ); |
||
92 | |||
93 | $payloadManipulatingSerializer->manipulateEventsOfClass( |
||
94 | 'CultuurNet\UDB3\Event\DescriptionTranslated', |
||
95 | function (array $serializedObject) { |
||
96 | $serializedObject['class'] = DescriptionTranslated::class; |
||
97 | |||
98 | $serializedObject = self::replaceEventIdWithItemId($serializedObject); |
||
99 | |||
100 | return $serializedObject; |
||
101 | } |
||
102 | ); |
||
103 | |||
104 | /* |
||
105 | * LABEL EVENTS |
||
106 | */ |
||
107 | |||
108 | $payloadManipulatingSerializer->manipulateEventsOfClass( |
||
109 | 'CultuurNet\UDB3\Label\Events\MadeInvisible', |
||
110 | function (array $serializedObject) use ($labelRepository) { |
||
111 | return self::addLabelName($serializedObject, $labelRepository); |
||
112 | } |
||
113 | ); |
||
114 | |||
115 | $payloadManipulatingSerializer->manipulateEventsOfClass( |
||
116 | 'CultuurNet\UDB3\Label\Events\MadeVisible', |
||
117 | function (array $serializedObject) use ($labelRepository) { |
||
118 | return self::addLabelName($serializedObject, $labelRepository); |
||
119 | } |
||
120 | ); |
||
121 | |||
122 | $payloadManipulatingSerializer->manipulateEventsOfClass( |
||
123 | 'CultuurNet\UDB3\Label\Events\MadePrivate', |
||
124 | function (array $serializedObject) use ($labelRepository) { |
||
125 | return self::addLabelName($serializedObject, $labelRepository); |
||
126 | } |
||
127 | ); |
||
128 | |||
129 | $payloadManipulatingSerializer->manipulateEventsOfClass( |
||
130 | 'CultuurNet\UDB3\Label\Events\MadePublic', |
||
131 | function (array $serializedObject) use ($labelRepository) { |
||
132 | return self::addLabelName($serializedObject, $labelRepository); |
||
133 | } |
||
134 | ); |
||
135 | |||
136 | $payloadManipulatingSerializer->manipulateEventsOfClass( |
||
137 | 'CultuurNet\UDB3\Organizer\Events\LabelAdded', |
||
138 | function (array $serializedObject) use ($labelRepository) { |
||
139 | return self::fixOrganizerLabelEvent($serializedObject, $labelRepository); |
||
140 | } |
||
141 | ); |
||
142 | |||
143 | $payloadManipulatingSerializer->manipulateEventsOfClass( |
||
144 | 'CultuurNet\UDB3\Organizer\Events\LabelRemoved', |
||
145 | function (array $serializedObject) use ($labelRepository) { |
||
146 | return self::fixOrganizerLabelEvent($serializedObject, $labelRepository); |
||
147 | } |
||
148 | ); |
||
149 | |||
150 | $payloadManipulatingSerializer->manipulateEventsOfClass( |
||
151 | 'CultuurNet\UDB3\Event\Events\EventWasLabelled', |
||
152 | function (array $serializedObject) { |
||
153 | $serializedObject['class'] = LabelAdded::class; |
||
154 | |||
155 | $serializedObject = self::replaceEventIdWithItemId($serializedObject); |
||
156 | |||
157 | return $serializedObject; |
||
158 | } |
||
159 | ); |
||
160 | |||
161 | $payloadManipulatingSerializer->manipulateEventsOfClass( |
||
162 | 'CultuurNet\UDB3\Event\EventWasTagged', |
||
163 | function (array $serializedObject) { |
||
164 | $serializedObject['class'] = LabelAdded::class; |
||
165 | |||
166 | $serializedObject = self::replaceEventIdWithItemId($serializedObject); |
||
167 | |||
168 | $serializedObject = self::replaceKeywordWithLabel($serializedObject); |
||
169 | |||
170 | return $serializedObject; |
||
171 | } |
||
172 | ); |
||
173 | |||
174 | $payloadManipulatingSerializer->manipulateEventsOfClass( |
||
175 | 'CultuurNet\UDB3\Event\TagErased', |
||
176 | function (array $serializedObject) { |
||
177 | $serializedObject['class'] = LabelRemoved::class; |
||
178 | |||
179 | $serializedObject = self::replaceEventIdWithItemId($serializedObject); |
||
180 | |||
181 | $serializedObject = self::replaceKeywordWithLabel($serializedObject); |
||
182 | |||
183 | return $serializedObject; |
||
184 | } |
||
185 | ); |
||
186 | |||
187 | $payloadManipulatingSerializer->manipulateEventsOfClass( |
||
188 | 'CultuurNet\UDB3\Event\Events\Unlabelled', |
||
189 | function (array $serializedObject) { |
||
190 | $serializedObject['class'] = LabelRemoved::class; |
||
191 | |||
192 | $serializedObject = self::replaceEventIdWithItemId($serializedObject); |
||
193 | |||
194 | return $serializedObject; |
||
195 | } |
||
196 | ); |
||
197 | |||
198 | /** |
||
199 | * UBD2 IMPORT |
||
200 | */ |
||
201 | |||
202 | $payloadManipulatingSerializer->manipulateEventsOfClass( |
||
203 | 'CultuurNet\UDB3\Event\EventImportedFromUDB2', |
||
204 | function (array $serializedObject) { |
||
205 | $serializedObject['class'] = EventImportedFromUDB2::class; |
||
206 | |||
207 | return $serializedObject; |
||
208 | } |
||
209 | ); |
||
210 | |||
211 | /** |
||
212 | * PLACE FACILITIES EVENT |
||
213 | */ |
||
214 | $payloadManipulatingSerializer->manipulateEventsOfClass( |
||
215 | 'CultuurNet\UDB3\Place\Events\FacilitiesUpdated', |
||
216 | function (array $serializedObject) { |
||
217 | $serializedObject = self::replacePlaceIdWithItemId($serializedObject); |
||
218 | |||
219 | return $serializedObject; |
||
220 | } |
||
221 | ); |
||
222 | |||
223 | /** |
||
224 | * GEOCOORDINATES UPDATED EVENT |
||
225 | */ |
||
226 | $payloadManipulatingSerializer->manipulateEventsOfClass( |
||
227 | 'CultuurNet\UDB3\Place\Events\GeoCoordinatesUpdated', |
||
228 | function (array $serializedObject) { |
||
229 | $serializedObject = self::replacePlaceIdWithItemId($serializedObject); |
||
230 | |||
231 | return $serializedObject; |
||
232 | } |
||
233 | ); |
||
234 | |||
235 | /** |
||
236 | * EventEvent to AbstractEvent (Offer) |
||
237 | */ |
||
238 | $refactoredEventEvents = [ |
||
239 | EventBookingInfoUpdated::class, |
||
240 | EventTypicalAgeRangeDeleted::class, |
||
241 | EventTypicalAgeRangeUpdated::class, |
||
242 | EventContactPointUpdated::class, |
||
243 | MajorInfoUpdated::class, |
||
244 | EventOrganizerUpdated::class, |
||
245 | EventOrganizerDeleted::class, |
||
246 | EventDescriptionUpdated::class, |
||
247 | EventDeleted::class, |
||
248 | ]; |
||
249 | |||
250 | foreach ($refactoredEventEvents as $refactoredEventEvent) { |
||
251 | $payloadManipulatingSerializer->manipulateEventsOfClass( |
||
252 | $refactoredEventEvent, |
||
253 | function (array $serializedObject) { |
||
254 | $serializedObject = self::replaceEventIdWithItemId($serializedObject); |
||
255 | return $serializedObject; |
||
256 | } |
||
257 | ); |
||
258 | } |
||
259 | |||
260 | /** |
||
261 | * PlaceEvent to AbstractEvent (Offer) |
||
262 | */ |
||
263 | $refactoredPlaceEvents = [ |
||
264 | PlaceOrganizerUpdated::class, |
||
265 | PlaceOrganizerDeleted::class, |
||
266 | PlaceBookingInfoUpdated::class, |
||
267 | PlaceTypicalAgeRangeDeleted::class, |
||
268 | PlaceTypicalAgeRangeUpdated::class, |
||
269 | PlaceContactPointUpdated::class, |
||
270 | PlaceDescriptionUpdated::class, |
||
271 | PlaceDeleted::class, |
||
272 | ]; |
||
273 | |||
274 | foreach ($refactoredPlaceEvents as $refactoredPlaceEvent) { |
||
275 | $payloadManipulatingSerializer->manipulateEventsOfClass( |
||
276 | $refactoredPlaceEvent, |
||
277 | function (array $serializedObject) { |
||
278 | $serializedObject = self::replacePlaceIdWithItemId($serializedObject); |
||
279 | return $serializedObject; |
||
280 | } |
||
281 | ); |
||
282 | } |
||
283 | |||
284 | return $payloadManipulatingSerializer; |
||
285 | } |
||
286 | |||
389 |