| Conditions | 45 | 
| Paths | 1 | 
| Total Lines | 386 | 
| Code Lines | 256 | 
| Lines | 34 | 
| Ratio | 8.81 % | 
| 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  | 
            ||
| 173 | protected function columns()  | 
            ||
| 174 |     { | 
            ||
| 175 | $formatter = $this;  | 
            ||
| 176 |         $contactPoint = function (\stdClass $event) use ($formatter) { | 
            ||
| 177 | return $formatter->contactPoint($event);  | 
            ||
| 178 | };  | 
            ||
| 179 | |||
| 180 | return [  | 
            ||
| 181 | 'id' => [  | 
            ||
| 182 | 'name' => 'id',  | 
            ||
| 183 |                 'include' => function ($event) { | 
            ||
| 184 |                     $eventUri = $event->{'@id'}; | 
            ||
| 185 |                     $uriParts = explode('/', $eventUri); | 
            ||
| 186 | $eventId = array_pop($uriParts);  | 
            ||
| 187 | |||
| 188 | return $eventId;  | 
            ||
| 189 | },  | 
            ||
| 190 | 'property' => 'id'  | 
            ||
| 191 | ],  | 
            ||
| 192 | 'name' => [  | 
            ||
| 193 | 'name' => 'titel',  | 
            ||
| 194 |                 'include' => function ($event) { | 
            ||
| 195 |                     if ($event->name) { | 
            ||
| 196 | return reset($event->name);  | 
            ||
| 197 | }  | 
            ||
| 198 | },  | 
            ||
| 199 | 'property' => 'name'  | 
            ||
| 200 | ],  | 
            ||
| 201 | 'creator' => [  | 
            ||
| 202 | 'name' => 'auteur',  | 
            ||
| 203 |                 'include' => function ($event) { | 
            ||
| 204 | return $event->creator;  | 
            ||
| 205 | },  | 
            ||
| 206 | 'property' => 'creator'  | 
            ||
| 207 | ],  | 
            ||
| 208 | 'bookingInfo.price' => [  | 
            ||
| 209 | 'name' => 'prijs',  | 
            ||
| 210 | View Code Duplication |                 'include' => function ($event) { | 
            |
| 
                                                                                                    
                        
                         | 
                |||
| 211 |                     if (property_exists($event, 'bookingInfo') && is_array($event->bookingInfo)) { | 
            ||
| 212 | $first = reset($event->bookingInfo);  | 
            ||
| 213 |                         if (is_object($first) && property_exists($first, 'price')) { | 
            ||
| 214 | return $first->price;  | 
            ||
| 215 | }  | 
            ||
| 216 | }  | 
            ||
| 217 | },  | 
            ||
| 218 | 'property' => 'bookingInfo'  | 
            ||
| 219 | ],  | 
            ||
| 220 | 'kansentarief' => [  | 
            ||
| 221 | 'name' => 'kansentarief',  | 
            ||
| 222 |                 'include' => function ($event) { | 
            ||
| 223 |                     $eventUri = $event->{'@id'}; | 
            ||
| 224 |                     $uriParts = explode('/', $eventUri); | 
            ||
| 225 | $eventId = array_pop($uriParts);  | 
            ||
| 226 | |||
| 227 | $uitpasInfo = $this->uitpas->getEventInfo($eventId);  | 
            ||
| 228 |                     if ($uitpasInfo) { | 
            ||
| 229 | $uitpasInfo = $this->uitpasInfoFormatter->format($uitpasInfo);  | 
            ||
| 230 | |||
| 231 |                         $cardSystems = array_reduce($uitpasInfo['prices'], function ($cardSystems, $tariff) { | 
            ||
| 232 | $cardSystem = isset($cardSystems[$tariff['cardSystem']]) ? $cardSystems[$tariff['cardSystem']] : '';  | 
            ||
| 233 | $cardSystem = empty($cardSystem)  | 
            ||
| 234 | ? $tariff['cardSystem'] .': € ' . $tariff['price']  | 
            ||
| 235 | : $cardSystem . ' / € ' . $tariff['price'];  | 
            ||
| 236 | |||
| 237 | $cardSystems[$tariff['cardSystem']] = $cardSystem;  | 
            ||
| 238 | return $cardSystems;  | 
            ||
| 239 | }, []);  | 
            ||
| 240 | |||
| 241 |                         $formattedTariffs = array_reduce($cardSystems, function ($tariffs, $cardSystemPrices) { | 
            ||
| 242 | return $tariffs ? $tariffs . ' | ' . $cardSystemPrices : $cardSystemPrices;  | 
            ||
| 243 | });  | 
            ||
| 244 | |||
| 245 |                         if (!empty($formattedTariffs)) { | 
            ||
| 246 | return $formattedTariffs;  | 
            ||
| 247 | }  | 
            ||
| 248 | }  | 
            ||
| 249 | },  | 
            ||
| 250 | 'property' => 'kansentarief'  | 
            ||
| 251 | ],  | 
            ||
| 252 | 'bookingInfo.url' => [  | 
            ||
| 253 | 'name' => 'ticket link',  | 
            ||
| 254 | View Code Duplication |                 'include' => function ($event) { | 
            |
| 255 |                     if (property_exists($event, 'bookingInfo')) { | 
            ||
| 256 | $first = reset($event->bookingInfo);  | 
            ||
| 257 |                         if (is_object($first) && property_exists($first, 'url')) { | 
            ||
| 258 | return $first->url;  | 
            ||
| 259 | }  | 
            ||
| 260 | }  | 
            ||
| 261 | },  | 
            ||
| 262 | 'property' => 'bookingInfo'  | 
            ||
| 263 | ],  | 
            ||
| 264 | 'description' => [  | 
            ||
| 265 | 'name' => 'omschrijving',  | 
            ||
| 266 |                 'include' => function ($event) { | 
            ||
| 267 |                     if (property_exists($event, 'description')) { | 
            ||
| 268 | $description = reset($event->description);  | 
            ||
| 269 | |||
| 270 | // the following preg replace statements will strip unwanted line-breaking characters  | 
            ||
| 271 | // except for markup  | 
            ||
| 272 | |||
| 273 | // do not add a whitespace when a line break follows a break tag  | 
            ||
| 274 |                         $description = preg_replace('/<br\ ?\/?>\s+/', '<br>', $description); | 
            ||
| 275 | |||
| 276 | // replace all leftover line breaks with a space to prevent words from sticking together  | 
            ||
| 277 |                         $description = trim(preg_replace('/\s+/', ' ', $description)); | 
            ||
| 278 | |||
| 279 | return $this->htmlFilter->filter($description);  | 
            ||
| 280 | }  | 
            ||
| 281 | },  | 
            ||
| 282 | 'property' => 'description'  | 
            ||
| 283 | ],  | 
            ||
| 284 | 'organizer' => [  | 
            ||
| 285 | 'name' => 'organisatie',  | 
            ||
| 286 |                 'include' => function ($event) { | 
            ||
| 287 | if (property_exists($event, 'organizer') &&  | 
            ||
| 288 | isset($event->organizer->name)  | 
            ||
| 289 |                     ) { | 
            ||
| 290 | return $event->organizer->name;  | 
            ||
| 291 | }  | 
            ||
| 292 | },  | 
            ||
| 293 | 'property' => 'organizer'  | 
            ||
| 294 | ],  | 
            ||
| 295 | 'calendarSummary' => [  | 
            ||
| 296 | 'name' => 'tijdsinformatie',  | 
            ||
| 297 |                 'include' => function ($event) { | 
            ||
| 298 | return $event->calendarSummary;  | 
            ||
| 299 | },  | 
            ||
| 300 | 'property' => 'calendarSummary'  | 
            ||
| 301 | ],  | 
            ||
| 302 | 'labels' => [  | 
            ||
| 303 | 'name' => 'labels',  | 
            ||
| 304 |                 'include' => function ($event) { | 
            ||
| 305 |                     if (isset($event->labels)) { | 
            ||
| 306 |                         return implode(';', $event->labels); | 
            ||
| 307 | }  | 
            ||
| 308 | },  | 
            ||
| 309 | 'property' => 'labels'  | 
            ||
| 310 | ],  | 
            ||
| 311 | 'typicalAgeRange' => [  | 
            ||
| 312 | 'name' => 'leeftijd',  | 
            ||
| 313 |                 'include' => function ($event) { | 
            ||
| 314 | return $event->typicalAgeRange;  | 
            ||
| 315 | },  | 
            ||
| 316 | 'property' => 'typicalAgeRange'  | 
            ||
| 317 | ],  | 
            ||
| 318 | 'performer' => [  | 
            ||
| 319 | 'name' => 'uitvoerders',  | 
            ||
| 320 |                 'include' => function ($event) { | 
            ||
| 321 |                     if (property_exists($event, 'performer')) { | 
            ||
| 322 | $performerNames = [];  | 
            ||
| 323 |                         foreach ($event->performer as $performer) { | 
            ||
| 324 | $performerNames[] = $performer->name;  | 
            ||
| 325 | }  | 
            ||
| 326 | |||
| 327 |                         return implode(';', $performerNames); | 
            ||
| 328 | }  | 
            ||
| 329 | },  | 
            ||
| 330 | 'property' => 'performer'  | 
            ||
| 331 | ],  | 
            ||
| 332 | 'language' => [  | 
            ||
| 333 | 'name' => 'taal van het aanbod',  | 
            ||
| 334 |                 'include' => function ($event) { | 
            ||
| 335 |                     if (property_exists($event, 'language')) { | 
            ||
| 336 |                         return implode(';', $event->language); | 
            ||
| 337 | }  | 
            ||
| 338 | },  | 
            ||
| 339 | 'property' => 'language'  | 
            ||
| 340 | ],  | 
            ||
| 341 | 'terms.theme' => [  | 
            ||
| 342 | 'name' => 'thema',  | 
            ||
| 343 | View Code Duplication |                 'include' => function ($event) { | 
            |
| 344 |                     if (property_exists($event, 'terms')) { | 
            ||
| 345 |                         foreach ($event->terms as $term) { | 
            ||
| 346 |                             if ($term->domain && $term->label && $term->domain == 'theme') { | 
            ||
| 347 | return $term->label;  | 
            ||
| 348 | }  | 
            ||
| 349 | }  | 
            ||
| 350 | }  | 
            ||
| 351 | },  | 
            ||
| 352 | 'property' => 'terms.theme'  | 
            ||
| 353 | ],  | 
            ||
| 354 | 'terms.eventtype' => [  | 
            ||
| 355 | 'name' => 'soort aanbod',  | 
            ||
| 356 | View Code Duplication |                 'include' => function ($event) { | 
            |
| 357 |                     if (property_exists($event, 'terms')) { | 
            ||
| 358 |                         foreach ($event->terms as $term) { | 
            ||
| 359 |                             if ($term->domain && $term->label && $term->domain == 'eventtype') { | 
            ||
| 360 | return $term->label;  | 
            ||
| 361 | }  | 
            ||
| 362 | }  | 
            ||
| 363 | }  | 
            ||
| 364 | },  | 
            ||
| 365 | 'property' => 'terms.eventtype'  | 
            ||
| 366 | ],  | 
            ||
| 367 | 'created' => [  | 
            ||
| 368 | 'name' => 'datum aangemaakt',  | 
            ||
| 369 |                 'include' => function ($event) { | 
            ||
| 370 |                     if (!empty($event->created)) { | 
            ||
| 371 | return $this->formatDate($event->created);  | 
            ||
| 372 |                     } else { | 
            ||
| 373 | return '';  | 
            ||
| 374 | }  | 
            ||
| 375 | },  | 
            ||
| 376 | 'property' => 'created'  | 
            ||
| 377 | ],  | 
            ||
| 378 | 'modified' => [  | 
            ||
| 379 | 'name' => 'datum laatste aanpassing',  | 
            ||
| 380 |                 'include' => function ($event) { | 
            ||
| 381 |                     if (!empty($event->modified)) { | 
            ||
| 382 | return $this->formatDate($event->modified);  | 
            ||
| 383 |                     } else { | 
            ||
| 384 | return '';  | 
            ||
| 385 | }  | 
            ||
| 386 | },  | 
            ||
| 387 | 'property' => 'modified'  | 
            ||
| 388 | ],  | 
            ||
| 389 | 'available' => [  | 
            ||
| 390 | 'name' => 'embargodatum',  | 
            ||
| 391 |                 'include' => function ($event) { | 
            ||
| 392 |                     if (!empty($event->available)) { | 
            ||
| 393 | return $this->formatDateWithoutTime($event->available);  | 
            ||
| 394 |                     } else { | 
            ||
| 395 | return '';  | 
            ||
| 396 | }  | 
            ||
| 397 | },  | 
            ||
| 398 | 'property' => 'available'  | 
            ||
| 399 | ],  | 
            ||
| 400 | 'startDate' => [  | 
            ||
| 401 | 'name' => 'startdatum',  | 
            ||
| 402 |                 'include' => function ($event) { | 
            ||
| 403 |                     if (!empty($event->startDate)) { | 
            ||
| 404 | return $this->formatDate($event->startDate);  | 
            ||
| 405 |                     } else { | 
            ||
| 406 | return '';  | 
            ||
| 407 | }  | 
            ||
| 408 | },  | 
            ||
| 409 | 'property' => 'startDate'  | 
            ||
| 410 | ],  | 
            ||
| 411 | 'endDate' => [  | 
            ||
| 412 | 'name' => 'einddatum',  | 
            ||
| 413 |                 'include' => function ($event) { | 
            ||
| 414 |                     if (!empty($event->endDate)) { | 
            ||
| 415 | return $this->formatDate($event->endDate);  | 
            ||
| 416 |                     } else { | 
            ||
| 417 | return '';  | 
            ||
| 418 | }  | 
            ||
| 419 | },  | 
            ||
| 420 | 'property' => 'endDate'  | 
            ||
| 421 | ],  | 
            ||
| 422 | 'calendarType' => [  | 
            ||
| 423 | 'name' => 'tijd type',  | 
            ||
| 424 |                 'include' => function ($event) { | 
            ||
| 425 | return $event->calendarType;  | 
            ||
| 426 | },  | 
            ||
| 427 | 'property' => 'calendarType'  | 
            ||
| 428 | ],  | 
            ||
| 429 | 'location' => [  | 
            ||
| 430 | 'name' => 'locatie naam',  | 
            ||
| 431 |                 'include' => function ($event) { | 
            ||
| 432 |                     if (property_exists($event, 'location') && isset($event->location->name)) { | 
            ||
| 433 | return reset($event->location->name);  | 
            ||
| 434 | }  | 
            ||
| 435 | },  | 
            ||
| 436 | 'property' => 'location'  | 
            ||
| 437 | ],  | 
            ||
| 438 | 'address.streetAddress' => [  | 
            ||
| 439 | 'name' => 'straat',  | 
            ||
| 440 |                 'include' => function ($event) { | 
            ||
| 441 |                     if (isset($event->location->address->streetAddress)) { | 
            ||
| 442 | return $event->location->address->streetAddress;  | 
            ||
| 443 | }  | 
            ||
| 444 | },  | 
            ||
| 445 | 'property' => 'address.streetAddress'  | 
            ||
| 446 | ],  | 
            ||
| 447 | 'address.postalCode' => [  | 
            ||
| 448 | 'name' => 'postcode',  | 
            ||
| 449 |                 'include' => function ($event) { | 
            ||
| 450 |                     if (isset($event->location->address->postalCode)) { | 
            ||
| 451 | return $event->location->address->postalCode;  | 
            ||
| 452 | }  | 
            ||
| 453 | },  | 
            ||
| 454 | 'property' => 'address.postalCode'  | 
            ||
| 455 | ],  | 
            ||
| 456 | 'address.addressLocality' => [  | 
            ||
| 457 | 'name' => 'gemeente',  | 
            ||
| 458 |                 'include' => function ($event) { | 
            ||
| 459 |                     if (isset($event->location->address->addressLocality)) { | 
            ||
| 460 | return $event->location->address->addressLocality;  | 
            ||
| 461 | }  | 
            ||
| 462 | },  | 
            ||
| 463 | 'property' => 'address.addressLocality'  | 
            ||
| 464 | ],  | 
            ||
| 465 | 'address.addressCountry' => [  | 
            ||
| 466 | 'name' => 'land',  | 
            ||
| 467 |                 'include' => function ($event) { | 
            ||
| 468 |                     if (isset($event->location->address->addressCountry)) { | 
            ||
| 469 | return $event->location->address->addressCountry;  | 
            ||
| 470 | }  | 
            ||
| 471 | },  | 
            ||
| 472 | 'property' => 'address.addressCountry'  | 
            ||
| 473 | ],  | 
            ||
| 474 | 'image' => [  | 
            ||
| 475 | 'name' => 'afbeelding',  | 
            ||
| 476 |                 'include' => function ($event) { | 
            ||
| 477 | return !empty($event->image) ? $event->image : '';  | 
            ||
| 478 | },  | 
            ||
| 479 | 'property' => 'image'  | 
            ||
| 480 | ],  | 
            ||
| 481 | 'sameAs' => [  | 
            ||
| 482 | 'name' => 'externe ids',  | 
            ||
| 483 |                 'include' => function ($event) { | 
            ||
| 484 |                     if (property_exists($event, 'sameAs')) { | 
            ||
| 485 | $ids = array();  | 
            ||
| 486 | |||
| 487 |                         foreach ($event->sameAs as $externalId) { | 
            ||
| 488 | $ids[] = $externalId;  | 
            ||
| 489 | }  | 
            ||
| 490 | |||
| 491 |                         return implode("\r\n", $ids); | 
            ||
| 492 | }  | 
            ||
| 493 | },  | 
            ||
| 494 | 'property' => 'sameAs'  | 
            ||
| 495 | ],  | 
            ||
| 496 | 'contactPoint.email' => [  | 
            ||
| 497 | 'name' => 'e-mail',  | 
            ||
| 498 |                 'include' => function ($event) use ($contactPoint) { | 
            ||
| 499 | return $this->listJsonldProperty(  | 
            ||
| 500 | $contactPoint($event),  | 
            ||
| 501 | 'email'  | 
            ||
| 502 | );  | 
            ||
| 503 | },  | 
            ||
| 504 | 'property' => 'contactPoint'  | 
            ||
| 505 | ],  | 
            ||
| 506 | 'contactPoint.telephone' => [  | 
            ||
| 507 | 'name' => 'telefoon',  | 
            ||
| 508 |                 'include' => function ($event) use ($contactPoint) { | 
            ||
| 509 | return $this->listJsonldProperty(  | 
            ||
| 510 | $contactPoint($event),  | 
            ||
| 511 | 'telephone'  | 
            ||
| 512 | );  | 
            ||
| 513 | },  | 
            ||
| 514 | 'property' => 'contactPoint'  | 
            ||
| 515 | ],  | 
            ||
| 516 | 'contactPoint.url' => [  | 
            ||
| 517 | 'name' => 'url',  | 
            ||
| 518 |                 'include' => function ($event) use ($contactPoint) { | 
            ||
| 519 | $contactUrls = $this->listJsonldProperty(  | 
            ||
| 520 | $contactPoint($event),  | 
            ||
| 521 | 'url'  | 
            ||
| 522 | );  | 
            ||
| 523 |                     return implode("\r\n", $contactUrls); | 
            ||
| 524 | },  | 
            ||
| 525 | 'property' => 'contactPoint'  | 
            ||
| 526 | ],  | 
            ||
| 527 | 'contactPoint.reservations.email' => [  | 
            ||
| 528 | 'name' => 'e-mail reservaties',  | 
            ||
| 529 |                 'include' => function ($event) use ($contactPoint) { | 
            ||
| 530 | return $this->listJsonldProperty(  | 
            ||
| 531 | $contactPoint($event, 'Reservations'),  | 
            ||
| 532 | 'email'  | 
            ||
| 533 | );  | 
            ||
| 534 | },  | 
            ||
| 535 | 'property' => 'contactPoint'  | 
            ||
| 536 | ],  | 
            ||
| 537 | 'contactPoint.reservations.telephone' => [  | 
            ||
| 538 | 'name' => 'telefoon reservaties',  | 
            ||
| 539 |                 'include' => function ($event) use ($contactPoint) { | 
            ||
| 540 | return $this->listJsonldProperty(  | 
            ||
| 541 | $contactPoint($event, 'Reservations'),  | 
            ||
| 542 | 'telephone'  | 
            ||
| 543 | );  | 
            ||
| 544 | },  | 
            ||
| 545 | 'property' => 'contactPoint'  | 
            ||
| 546 | ],  | 
            ||
| 547 | 'contactPoint.reservations.url' => [  | 
            ||
| 548 | 'name' => 'online reservaties',  | 
            ||
| 549 |                 'include' => function ($event) use ($contactPoint) { | 
            ||
| 550 | return $this->listJsonldProperty(  | 
            ||
| 551 | $contactPoint($event, 'Reservations'),  | 
            ||
| 552 | 'url'  | 
            ||
| 553 | );  | 
            ||
| 554 | },  | 
            ||
| 555 | 'property' => 'contactPoint'  | 
            ||
| 556 | ],  | 
            ||
| 557 | ];  | 
            ||
| 558 | }  | 
            ||
| 559 | |||
| 591 | 
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.