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