| Conditions | 1 |
| Paths | 1 |
| Total Lines | 51 |
| 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 |
||
| 11 | public function __construct($name, ServiceManager $sm, Translator $translator) |
||
| 12 | { |
||
| 13 | $this->setServiceManager($sm); |
||
| 14 | $entityManager = $sm->get('doctrine.entitymanager.orm_default'); |
||
| 15 | |||
| 16 | // having to fix a Doctrine-module bug :( https://github.com/doctrine/DoctrineModule/issues/180 |
||
| 17 | $hydrator = new DoctrineHydrator($entityManager, 'PlaygroundGame\Entity\Memory'); |
||
| 18 | $hydrator->addStrategy('partner', new \PlaygroundCore\Stdlib\Hydrator\Strategy\ObjectStrategy()); |
||
| 19 | $this->setHydrator($hydrator); |
||
| 20 | |||
| 21 | parent::__construct($name, $sm, $translator); |
||
| 22 | |||
| 23 | $this->add(array( |
||
| 24 | 'name' => 'victoryConditions', |
||
| 25 | 'type' => 'Zend\Form\Element\Text', |
||
| 26 | 'attributes' => array( |
||
| 27 | 'placeholder' => $translator->translate('% good picks vs mistakes', 'playgroundgame'), |
||
| 28 | 'id' => 'victoryConditions', |
||
| 29 | ), |
||
| 30 | 'options' => array( |
||
| 31 | 'label' => $translator->translate('Victory conditions', 'playgroundgame'), |
||
| 32 | ), |
||
| 33 | )); |
||
| 34 | |||
| 35 | // Adding an empty upload field to be able to correctly handle this on |
||
| 36 | // the service side. |
||
| 37 | $this->add(array( |
||
| 38 | 'name' => 'uploadBackImage', |
||
| 39 | 'attributes' => array( |
||
| 40 | 'type' => 'file', |
||
| 41 | ), |
||
| 42 | 'options' => array( |
||
| 43 | 'label' => $translator->translate('Back card image', 'playgroundgame'), |
||
| 44 | ), |
||
| 45 | )); |
||
| 46 | $this->add(array( |
||
| 47 | 'name' => 'backImage', |
||
| 48 | 'type' => 'Zend\Form\Element\Hidden', |
||
| 49 | 'attributes' => array( |
||
| 50 | 'value' => '', |
||
| 51 | ), |
||
| 52 | )); |
||
| 53 | $this->add(array( |
||
| 54 | 'name' => 'deleteBackImage', |
||
| 55 | 'type' => 'Zend\Form\Element\Hidden', |
||
| 56 | 'attributes' => array( |
||
| 57 | 'value' => '', |
||
| 58 | 'class' => 'delete_scratch_image', |
||
| 59 | ), |
||
| 60 | )); |
||
| 61 | } |
||
| 62 | } |
||
| 63 |