Conditions | 2 |
Paths | 1 |
Total Lines | 385 |
Code Lines | 231 |
Lines | 71 |
Ratio | 18.44 % |
Changes | 7 | ||
Bugs | 1 | Features | 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 |
||
377 | public function getServiceConfig() |
||
378 | { |
||
379 | return array( |
||
380 | 'aliases' => array( |
||
381 | // An alias for linking a partner service with PlaygroundGame without adherence |
||
382 | 'playgroundgame_partner_service' => 'playgroundpartnership_partner_service', |
||
383 | 'playgroundgame_message' => 'playgroundcore_message', |
||
384 | |||
385 | ), |
||
386 | |||
387 | 'invokables' => array( |
||
388 | 'playgroundgame_game_service' => 'PlaygroundGame\Service\Game', |
||
389 | 'playgroundgame_lottery_service' => 'PlaygroundGame\Service\Lottery', |
||
390 | 'playgroundgame_postvote_service' => 'PlaygroundGame\Service\PostVote', |
||
391 | 'playgroundgame_quiz_service' => 'PlaygroundGame\Service\Quiz', |
||
392 | 'playgroundgame_instantwin_service' => 'PlaygroundGame\Service\InstantWin', |
||
393 | 'playgroundgame_mission_service' => 'PlaygroundGame\Service\Mission', |
||
394 | 'playgroundgame_prize_service' => 'PlaygroundGame\Service\Prize', |
||
395 | 'playgroundgame_prizecategory_service' => 'PlaygroundGame\Service\PrizeCategory', |
||
396 | 'playgroundgame_prizecategoryuser_service' => 'PlaygroundGame\Service\PrizeCategoryUser', |
||
397 | ), |
||
398 | |||
399 | 'factories' => array( |
||
400 | 'playgroundgame_module_options' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
401 | $config = $sm->get('Configuration'); |
||
402 | |||
403 | return new Options\ModuleOptions( |
||
404 | isset($config['playgroundgame']) ? $config['playgroundgame'] : array() |
||
405 | ); |
||
406 | }, |
||
407 | |||
408 | 'playgroundgame_game_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
409 | $mapper = new \PlaygroundGame\Mapper\Game( |
||
410 | $sm->get('doctrine.entitymanager.orm_default'), |
||
411 | $sm->get('playgroundgame_module_options') |
||
412 | ); |
||
413 | |||
414 | return $mapper; |
||
415 | }, |
||
416 | |||
417 | 'playgroundgame_playerform_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
418 | $mapper = new \PlaygroundGame\Mapper\PlayerForm( |
||
419 | $sm->get('doctrine.entitymanager.orm_default'), |
||
420 | $sm->get('playgroundgame_module_options') |
||
421 | ); |
||
422 | |||
423 | return $mapper; |
||
424 | }, |
||
425 | |||
426 | 'playgroundgame_lottery_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
427 | $mapper = new \PlaygroundGame\Mapper\Lottery( |
||
428 | $sm->get('doctrine.entitymanager.orm_default'), |
||
429 | $sm->get('playgroundgame_module_options') |
||
430 | ); |
||
431 | |||
432 | return $mapper; |
||
433 | }, |
||
434 | |||
435 | 'playgroundgame_instantwin_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
436 | $mapper = new \PlaygroundGame\Mapper\InstantWin( |
||
437 | $sm->get('doctrine.entitymanager.orm_default'), |
||
438 | $sm->get('playgroundgame_module_options') |
||
439 | ); |
||
440 | |||
441 | return $mapper; |
||
442 | }, |
||
443 | |||
444 | 'playgroundgame_instantwinoccurrence_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
445 | $mapper = new \PlaygroundGame\Mapper\InstantWinOccurrence( |
||
446 | $sm->get('doctrine.entitymanager.orm_default'), |
||
447 | $sm->get('playgroundgame_module_options') |
||
448 | ); |
||
449 | |||
450 | return $mapper; |
||
451 | }, |
||
452 | |||
453 | 'playgroundgame_quiz_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
454 | $mapper = new \PlaygroundGame\Mapper\Quiz( |
||
455 | $sm->get('doctrine.entitymanager.orm_default'), |
||
456 | $sm->get('playgroundgame_module_options') |
||
457 | ); |
||
458 | |||
459 | return $mapper; |
||
460 | }, |
||
461 | |||
462 | 'playgroundgame_quizquestion_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
463 | $mapper = new \PlaygroundGame\Mapper\QuizQuestion( |
||
464 | $sm->get('doctrine.entitymanager.orm_default'), |
||
465 | $sm->get('playgroundgame_module_options') |
||
466 | ); |
||
467 | |||
468 | return $mapper; |
||
469 | }, |
||
470 | |||
471 | 'playgroundgame_quizanswer_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
472 | $mapper = new \PlaygroundGame\Mapper\QuizAnswer( |
||
473 | $sm->get('doctrine.entitymanager.orm_default'), |
||
474 | $sm->get('playgroundgame_module_options') |
||
475 | ); |
||
476 | |||
477 | return $mapper; |
||
478 | }, |
||
479 | |||
480 | 'playgroundgame_quizreply_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
481 | $mapper = new \PlaygroundGame\Mapper\QuizReply( |
||
482 | $sm->get('doctrine.entitymanager.orm_default'), |
||
483 | $sm->get('playgroundgame_module_options') |
||
484 | ); |
||
485 | |||
486 | return $mapper; |
||
487 | }, |
||
488 | |||
489 | 'playgroundgame_quizreplyanswer_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
490 | $mapper = new \PlaygroundGame\Mapper\QuizReplyAnswer( |
||
491 | $sm->get('doctrine.entitymanager.orm_default'), |
||
492 | $sm->get('playgroundgame_module_options') |
||
493 | ); |
||
494 | |||
495 | return $mapper; |
||
496 | }, |
||
497 | |||
498 | |||
499 | 'playgroundgame_entry_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
500 | $mapper = new \PlaygroundGame\Mapper\Entry( |
||
501 | $sm->get('doctrine.entitymanager.orm_default'), |
||
502 | $sm->get('playgroundgame_module_options') |
||
503 | ); |
||
504 | |||
505 | return $mapper; |
||
506 | }, |
||
507 | |||
508 | 'playgroundgame_postvote_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
509 | $mapper = new \PlaygroundGame\Mapper\PostVote( |
||
510 | $sm->get('doctrine.entitymanager.orm_default'), |
||
511 | $sm->get('playgroundgame_module_options') |
||
512 | ); |
||
513 | |||
514 | return $mapper; |
||
515 | }, |
||
516 | |||
517 | 'playgroundgame_postvoteform_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
518 | $mapper = new \PlaygroundGame\Mapper\PostVoteForm( |
||
519 | $sm->get('doctrine.entitymanager.orm_default'), |
||
520 | $sm->get('playgroundgame_module_options') |
||
521 | ); |
||
522 | |||
523 | return $mapper; |
||
524 | }, |
||
525 | |||
526 | 'playgroundgame_postvotepost_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
527 | $mapper = new \PlaygroundGame\Mapper\PostVotePost( |
||
528 | $sm->get('doctrine.entitymanager.orm_default'), |
||
529 | $sm->get('playgroundgame_module_options') |
||
530 | ); |
||
531 | |||
532 | return $mapper; |
||
533 | }, |
||
534 | |||
535 | 'playgroundgame_postvotepostelement_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
536 | $mapper = new \PlaygroundGame\Mapper\PostVotePostElement( |
||
537 | $sm->get('doctrine.entitymanager.orm_default'), |
||
538 | $sm->get('playgroundgame_module_options') |
||
539 | ); |
||
540 | |||
541 | return $mapper; |
||
542 | }, |
||
543 | |||
544 | 'playgroundgame_postvotevote_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
545 | $mapper = new \PlaygroundGame\Mapper\PostVoteVote( |
||
546 | $sm->get('doctrine.entitymanager.orm_default'), |
||
547 | $sm->get('playgroundgame_module_options') |
||
548 | ); |
||
549 | |||
550 | return $mapper; |
||
551 | }, |
||
552 | |||
553 | 'playgroundgame_prize_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
554 | $mapper = new \PlaygroundGame\Mapper\Prize( |
||
555 | $sm->get('doctrine.entitymanager.orm_default'), |
||
556 | $sm->get('playgroundgame_module_options') |
||
557 | ); |
||
558 | |||
559 | return $mapper; |
||
560 | }, |
||
561 | |||
562 | 'playgroundgame_prizecategory_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
563 | $mapper = new \PlaygroundGame\Mapper\PrizeCategory( |
||
564 | $sm->get('doctrine.entitymanager.orm_default'), |
||
565 | $sm->get('playgroundgame_module_options') |
||
566 | ); |
||
567 | |||
568 | return $mapper; |
||
569 | }, |
||
570 | |||
571 | 'playgroundgame_prizecategoryuser_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
572 | $mapper = new \PlaygroundGame\Mapper\PrizeCategoryUser( |
||
573 | $sm->get('doctrine.entitymanager.orm_default'), |
||
574 | $sm->get('playgroundgame_module_options') |
||
575 | ); |
||
576 | |||
577 | return $mapper; |
||
578 | }, |
||
579 | |||
580 | 'playgroundgame_invitation_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
581 | $mapper = new \PlaygroundGame\Mapper\Invitation( |
||
582 | $sm->get('doctrine.entitymanager.orm_default'), |
||
583 | $sm->get('playgroundgame_module_options') |
||
584 | ); |
||
585 | |||
586 | return $mapper; |
||
587 | }, |
||
588 | |||
589 | 'playgroundgame_mission_mapper' => function ($sm) { |
||
590 | $mapper = new Mapper\Mission( |
||
591 | $sm->get('doctrine.entitymanager.orm_default'), |
||
592 | $sm->get('playgroundgame_module_options') |
||
593 | ); |
||
594 | |||
595 | return $mapper; |
||
596 | }, |
||
597 | |||
598 | 'playgroundgame_mission_game_mapper' => function ($sm) { |
||
599 | $mapper = new Mapper\MissionGame( |
||
600 | $sm->get('doctrine.entitymanager.orm_default'), |
||
601 | $sm->get('playgroundgame_module_options') |
||
602 | ); |
||
603 | |||
604 | return $mapper; |
||
605 | }, |
||
606 | |||
607 | 'playgroundgame_mission_game_condition_mapper' => function ($sm) { |
||
608 | $mapper = new Mapper\MissionGameCondition( |
||
609 | $sm->get('doctrine.entitymanager.orm_default'), |
||
610 | $sm->get('playgroundgame_module_options') |
||
611 | ); |
||
612 | |||
613 | return $mapper; |
||
614 | }, |
||
615 | |||
616 | 'playgroundgame_mission_form' => function ($sm) { |
||
617 | $translator = $sm->get('translator'); |
||
618 | $form = new Form\Admin\Mission(null, $sm, $translator); |
||
619 | $mission = new Entity\Mission(); |
||
620 | $form->setInputFilter($mission->getInputFilter()); |
||
621 | |||
622 | return $form; |
||
623 | }, |
||
624 | |||
625 | View Code Duplication | 'playgroundgame_mission_game_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
626 | $translator = $sm->get('translator'); |
||
627 | $form = new Form\Admin\MissionGameFieldset(null, $sm, $translator); |
||
628 | $missionGame = new Entity\MissionGame(); |
||
629 | $form->setInputFilter($missionGame->getInputFilter()); |
||
630 | return $form; |
||
631 | }, |
||
632 | |||
633 | View Code Duplication | 'playgroundgame_game_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
634 | $translator = $sm->get('translator'); |
||
635 | $form = new Form\Admin\Game(null, $sm, $translator); |
||
636 | $game = new Entity\Game(); |
||
637 | $form->setInputFilter($game->getInputFilter()); |
||
638 | |||
639 | return $form; |
||
640 | }, |
||
641 | |||
642 | 'playgroundgame_register_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
643 | $translator = $sm->get('translator'); |
||
644 | $zfcUserOptions = $sm->get('zfcuser_module_options'); |
||
645 | $form = new Form\Frontend\Register(null, $zfcUserOptions, $translator, $sm); |
||
646 | $form->setInputFilter(new \ZfcUser\Form\RegisterFilter( |
||
647 | new \ZfcUser\Validator\NoRecordExists(array( |
||
648 | 'mapper' => $sm->get('zfcuser_user_mapper'), |
||
649 | 'key' => 'email' |
||
650 | )), |
||
651 | new \ZfcUser\Validator\NoRecordExists(array( |
||
652 | 'mapper' => $sm->get('zfcuser_user_mapper'), |
||
653 | 'key' => 'username' |
||
654 | )), |
||
655 | $zfcUserOptions |
||
656 | )); |
||
657 | |||
658 | return $form; |
||
659 | }, |
||
660 | |||
661 | 'playgroundgame_import_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
662 | $translator = $sm->get('translator'); |
||
663 | $form = new Form\Admin\Import(null, $sm, $translator); |
||
664 | |||
665 | return $form; |
||
666 | }, |
||
667 | |||
668 | View Code Duplication | 'playgroundgame_lottery_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
669 | $translator = $sm->get('translator'); |
||
670 | $form = new Form\Admin\Lottery(null, $sm, $translator); |
||
671 | $lottery = new Entity\Lottery(); |
||
672 | $form->setInputFilter($lottery->getInputFilter()); |
||
673 | |||
674 | return $form; |
||
675 | }, |
||
676 | |||
677 | View Code Duplication | 'playgroundgame_quiz_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
678 | $translator = $sm->get('translator'); |
||
679 | $form = new Form\Admin\Quiz(null, $sm, $translator); |
||
680 | $quiz = new Entity\Quiz(); |
||
681 | $form->setInputFilter($quiz->getInputFilter()); |
||
682 | |||
683 | return $form; |
||
684 | }, |
||
685 | |||
686 | View Code Duplication | 'playgroundgame_instantwin_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
687 | $translator = $sm->get('translator'); |
||
688 | $form = new Form\Admin\InstantWin(null, $sm, $translator); |
||
689 | $instantwin = new Entity\InstantWin(); |
||
690 | $form->setInputFilter($instantwin->getInputFilter()); |
||
691 | |||
692 | return $form; |
||
693 | }, |
||
694 | |||
695 | View Code Duplication | 'playgroundgame_quizquestion_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
696 | $translator = $sm->get('translator'); |
||
697 | $form = new Form\Admin\QuizQuestion(null, $sm, $translator); |
||
698 | $quizQuestion = new Entity\QuizQuestion(); |
||
699 | $form->setInputFilter($quizQuestion->getInputFilter()); |
||
700 | |||
701 | return $form; |
||
702 | }, |
||
703 | |||
704 | View Code Duplication | 'playgroundgame_instantwinoccurrence_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
705 | $translator = $sm->get('translator'); |
||
706 | $form = new Form\Admin\InstantWinOccurrence(null, $sm, $translator); |
||
707 | $instantwinOccurrence = new Entity\InstantWinOccurrence(); |
||
708 | $form->setInputFilter($instantwinOccurrence->getInputFilter()); |
||
709 | |||
710 | return $form; |
||
711 | }, |
||
712 | |||
713 | 'playgroundgame_instantwinoccurrenceimport_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
714 | $translator = $sm->get('translator'); |
||
715 | $form = new Form\Admin\InstantWinOccurrenceImport(null, $sm, $translator); |
||
716 | return $form; |
||
717 | }, |
||
718 | |||
719 | 'playgroundgame_instantwinoccurrencecode_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
720 | $translator = $sm->get('translator'); |
||
721 | $form = new Form\Frontend\InstantWinOccurrenceCode(null, $sm, $translator); |
||
722 | $filter = new Form\Frontend\InstantWinOccurrenceCodeFilter(); |
||
723 | $form->setInputFilter($filter); |
||
724 | return $form; |
||
725 | }, |
||
726 | |||
727 | View Code Duplication | 'playgroundgame_postvote_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
728 | $translator = $sm->get('translator'); |
||
729 | $form = new Form\Admin\PostVote(null, $sm, $translator); |
||
730 | $postVote = new Entity\PostVote(); |
||
731 | $form->setInputFilter($postVote->getInputFilter()); |
||
732 | |||
733 | return $form; |
||
734 | }, |
||
735 | |||
736 | View Code Duplication | 'playgroundgame_prizecategory_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
737 | $translator = $sm->get('translator'); |
||
738 | $form = new Form\Admin\PrizeCategory(null, $sm, $translator); |
||
739 | $prizeCategory = new Entity\PrizeCategory(); |
||
740 | $form->setInputFilter($prizeCategory->getInputFilter()); |
||
741 | |||
742 | return $form; |
||
743 | }, |
||
744 | |||
745 | 'playgroundgame_prizecategoryuser_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
746 | $translator = $sm->get('translator'); |
||
747 | $form = new Form\Frontend\PrizeCategoryUser(null, $sm, $translator); |
||
748 | |||
749 | return $form; |
||
750 | }, |
||
751 | |||
752 | 'playgroundgame_sharemail_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
||
753 | $translator = $sm->get('translator'); |
||
754 | $form = new Form\Frontend\ShareMail(null, $sm, $translator); |
||
755 | $form->setInputFilter(new Form\Frontend\ShareMailFilter()); |
||
756 | |||
757 | return $form; |
||
758 | }, |
||
759 | ), |
||
760 | ); |
||
761 | } |
||
762 | } |
||
763 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: