| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 104 | 
| 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  | 
            ||
| 12 | public function __construct($name, ServiceManager $serviceManager, Translator $translator)  | 
            ||
| 13 |     { | 
            ||
| 14 | parent::__construct($name);  | 
            ||
| 15 | |||
| 16 |         $this->setAttribute('method', 'post'); | 
            ||
| 17 |         $this->setAttribute('enctype', 'multipart/form-data'); | 
            ||
| 18 | |||
| 19 | $this->setServiceManager($serviceManager);  | 
            ||
| 20 | |||
| 21 | $this->add(array(  | 
            ||
| 22 | 'name' => 'memory_id',  | 
            ||
| 23 | 'type' => 'Zend\Form\Element\Hidden',  | 
            ||
| 24 | 'attributes' => array(  | 
            ||
| 25 | 'value' => 0,  | 
            ||
| 26 | ),  | 
            ||
| 27 | ));  | 
            ||
| 28 | |||
| 29 | $this->add(array(  | 
            ||
| 30 | 'name' => 'id',  | 
            ||
| 31 | 'type' => 'Zend\Form\Element\Hidden',  | 
            ||
| 32 | 'attributes' => array(  | 
            ||
| 33 | 'value' => 0,  | 
            ||
| 34 | ),  | 
            ||
| 35 | ));  | 
            ||
| 36 | |||
| 37 | $this->add(array(  | 
            ||
| 38 | 'name' => 'title',  | 
            ||
| 39 | 'options' => array(  | 
            ||
| 40 |                 'label' => $translator->translate('Title', 'playgroundgame'), | 
            ||
| 41 | ),  | 
            ||
| 42 | 'attributes' => array(  | 
            ||
| 43 | 'type' => 'text',  | 
            ||
| 44 | 'id' => 'title',  | 
            ||
| 45 | ),  | 
            ||
| 46 | ));  | 
            ||
| 47 | |||
| 48 | $this->add(array(  | 
            ||
| 49 | 'type' => 'Zend\Form\Element\Textarea',  | 
            ||
| 50 | 'name' => 'description',  | 
            ||
| 51 | 'options' => array(  | 
            ||
| 52 |                 'label' => $translator->translate('Description', 'playgroundgame'), | 
            ||
| 53 | ),  | 
            ||
| 54 | 'required' => false,  | 
            ||
| 55 | 'cols' => '40',  | 
            ||
| 56 | 'rows' => '10',  | 
            ||
| 57 | 'id' => 'description',  | 
            ||
| 58 | ));  | 
            ||
| 59 | |||
| 60 | // Adding an empty upload field to be able to correctly handle this on the service side.  | 
            ||
| 61 | $this->add(array(  | 
            ||
| 62 | 'name' => 'upload_image',  | 
            ||
| 63 | 'attributes' => array(  | 
            ||
| 64 | 'type' => 'file',  | 
            ||
| 65 | ),  | 
            ||
| 66 | 'options' => array(  | 
            ||
| 67 |                     'label' => $translator->translate('Image', 'playgroundgame'), | 
            ||
| 68 | 'label_attributes' => array(  | 
            ||
| 69 | 'class' => 'control-label',  | 
            ||
| 70 | ),  | 
            ||
| 71 | ),  | 
            ||
| 72 | ));  | 
            ||
| 73 | $this->add(array(  | 
            ||
| 74 | 'name' => 'image',  | 
            ||
| 75 | 'type' => 'Zend\Form\Element\Hidden',  | 
            ||
| 76 | 'attributes' => array(  | 
            ||
| 77 | 'value' => '',  | 
            ||
| 78 | ),  | 
            ||
| 79 | ));  | 
            ||
| 80 | $this->add(array(  | 
            ||
| 81 | 'name' => 'delete_image',  | 
            ||
| 82 | 'type' => 'Zend\Form\Element\Hidden',  | 
            ||
| 83 | 'attributes' => array(  | 
            ||
| 84 | 'value' => '',  | 
            ||
| 85 | 'class' => 'delete_image',  | 
            ||
| 86 | ),  | 
            ||
| 87 | ));  | 
            ||
| 88 | |||
| 89 | $this->add(array(  | 
            ||
| 90 | 'type' => 'Zend\Form\Element\Textarea',  | 
            ||
| 91 | 'name' => 'jsonData',  | 
            ||
| 92 | 'options' => array(  | 
            ||
| 93 |                 'label' => $translator->translate('Json Data', 'playgroundgame'), | 
            ||
| 94 | 'label_attributes' => array(  | 
            ||
| 95 | 'class' => 'control-label',  | 
            ||
| 96 | ),  | 
            ||
| 97 | ),  | 
            ||
| 98 | 'attributes' => array(  | 
            ||
| 99 | 'required' => false,  | 
            ||
| 100 | 'cols' => '40',  | 
            ||
| 101 | 'rows' => '10',  | 
            ||
| 102 | 'id' => 'jsonData',  | 
            ||
| 103 | ),  | 
            ||
| 104 | ));  | 
            ||
| 105 | |||
| 106 |         $submitElement = new Element\Button('submit'); | 
            ||
| 107 | $submitElement->setAttributes(array(  | 
            ||
| 108 | 'type' => 'submit',  | 
            ||
| 109 | 'class' => 'btn btn-primary',  | 
            ||
| 110 | ));  | 
            ||
| 111 | |||
| 112 | $this->add($submitElement, array(  | 
            ||
| 113 | 'priority' => -100,  | 
            ||
| 114 | ));  | 
            ||
| 115 | }  | 
            ||
| 116 | |||
| 142 | 
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: