| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 161 | 
| Code Lines | 106 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | 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  | 
            ||
| 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' => 'trading_card_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 | 'name' => 'type',  | 
            ||
| 50 | 'options' => array(  | 
            ||
| 51 |                 'label' => $translator->translate('Type (Collector / Standard)', 'playgroundgame'), | 
            ||
| 52 | ),  | 
            ||
| 53 | 'attributes' => array(  | 
            ||
| 54 | 'type' => 'text',  | 
            ||
| 55 | 'id' => 'type'  | 
            ||
| 56 | ),  | 
            ||
| 57 | ));  | 
            ||
| 58 | |||
| 59 | $this->add(array(  | 
            ||
| 60 | 'name' => 'family',  | 
            ||
| 61 | 'options' => array(  | 
            ||
| 62 |                 'label' => $translator->translate('Family', 'playgroundgame'), | 
            ||
| 63 | ),  | 
            ||
| 64 | 'attributes' => array(  | 
            ||
| 65 | 'type' => 'text',  | 
            ||
| 66 | 'id' => 'family'  | 
            ||
| 67 | ),  | 
            ||
| 68 | ));  | 
            ||
| 69 | |||
| 70 | $this->add(array(  | 
            ||
| 71 | 'name' => 'points',  | 
            ||
| 72 | 'options' => array(  | 
            ||
| 73 |                 'label' => $translator->translate('Points', 'playgroundgame'), | 
            ||
| 74 | ),  | 
            ||
| 75 | 'attributes' => array(  | 
            ||
| 76 | 'type' => 'text',  | 
            ||
| 77 | 'id' => 'points'  | 
            ||
| 78 | ),  | 
            ||
| 79 | ));  | 
            ||
| 80 | $this->add(array(  | 
            ||
| 81 | 'type' => 'Zend\Form\Element\Textarea',  | 
            ||
| 82 | 'name' => 'description',  | 
            ||
| 83 | 'options' => array(  | 
            ||
| 84 |                 'label' => $translator->translate('Description', 'playgroundgame'), | 
            ||
| 85 | ),  | 
            ||
| 86 | 'required' => false,  | 
            ||
| 87 | 'cols' => '40',  | 
            ||
| 88 | 'rows' => '10',  | 
            ||
| 89 | 'id' => 'description',  | 
            ||
| 90 | ));  | 
            ||
| 91 | |||
| 92 | $this->add(array(  | 
            ||
| 93 | 'name' => 'distribution',  | 
            ||
| 94 | 'options' => array(  | 
            ||
| 95 |                 'label' => $translator->translate('probability drawing', 'playgroundgame'), | 
            ||
| 96 | ),  | 
            ||
| 97 | 'attributes' => array(  | 
            ||
| 98 | 'type' => 'text',  | 
            ||
| 99 | 'id' => 'distribution'  | 
            ||
| 100 | ),  | 
            ||
| 101 | ));  | 
            ||
| 102 | |||
| 103 | // Adding an empty upload field to be able to correctly handle this on the service side.  | 
            ||
| 104 | $this->add(array(  | 
            ||
| 105 | 'name' => 'upload_image',  | 
            ||
| 106 | 'attributes' => array(  | 
            ||
| 107 | 'type' => 'file',  | 
            ||
| 108 | ),  | 
            ||
| 109 | 'options' => array(  | 
            ||
| 110 |                     'label' => $translator->translate('Image', 'playgroundgame'), | 
            ||
| 111 | 'label_attributes' => array(  | 
            ||
| 112 | 'class' => 'control-label',  | 
            ||
| 113 | ),  | 
            ||
| 114 | ),  | 
            ||
| 115 | ));  | 
            ||
| 116 | $this->add(array(  | 
            ||
| 117 | 'name' => 'image',  | 
            ||
| 118 | 'type' => 'Zend\Form\Element\Hidden',  | 
            ||
| 119 | 'attributes' => array(  | 
            ||
| 120 | 'value' => '',  | 
            ||
| 121 | ),  | 
            ||
| 122 | ));  | 
            ||
| 123 | $this->add(array(  | 
            ||
| 124 | 'name' => 'delete_image',  | 
            ||
| 125 | 'type' => 'Zend\Form\Element\Hidden',  | 
            ||
| 126 | 'attributes' => array(  | 
            ||
| 127 | 'value' => '',  | 
            ||
| 128 | 'class' => 'delete_image',  | 
            ||
| 129 | ),  | 
            ||
| 130 | ));  | 
            ||
| 131 | |||
| 132 | $this->add(array(  | 
            ||
| 133 | 'type' => 'Zend\Form\Element\DateTime',  | 
            ||
| 134 | 'name' => 'availability',  | 
            ||
| 135 | 'options' => array(  | 
            ||
| 136 |                     'label' => $translator->translate('Availability date', 'playgroundgame'), | 
            ||
| 137 | 'format' => 'd/m/Y H:i:s'  | 
            ||
| 138 | ),  | 
            ||
| 139 | 'attributes' => array(  | 
            ||
| 140 | 'type' => 'text',  | 
            ||
| 141 | 'class'=> 'datepicker',  | 
            ||
| 142 | 'id' => 'availability'  | 
            ||
| 143 | ),  | 
            ||
| 144 | ));  | 
            ||
| 145 | |||
| 146 | $this->add(array(  | 
            ||
| 147 | 'type' => 'Zend\Form\Element\Textarea',  | 
            ||
| 148 | 'name' => 'jsonData',  | 
            ||
| 149 | 'options' => array(  | 
            ||
| 150 |                 'label' => $translator->translate('Json Data', 'playgroundgame'), | 
            ||
| 151 | 'label_attributes' => array(  | 
            ||
| 152 | 'class' => 'control-label',  | 
            ||
| 153 | ),  | 
            ||
| 154 | ),  | 
            ||
| 155 | 'attributes' => array(  | 
            ||
| 156 | 'required' => false,  | 
            ||
| 157 | 'cols' => '40',  | 
            ||
| 158 | 'rows' => '10',  | 
            ||
| 159 | 'id' => 'jsonData',  | 
            ||
| 160 | ),  | 
            ||
| 161 | ));  | 
            ||
| 162 | |||
| 163 |         $submitElement = new Element\Button('submit'); | 
            ||
| 164 | $submitElement->setAttributes(array(  | 
            ||
| 165 | 'type' => 'submit',  | 
            ||
| 166 | 'class' => 'btn btn-primary',  | 
            ||
| 167 | ));  | 
            ||
| 168 | |||
| 169 | $this->add($submitElement, array(  | 
            ||
| 170 | 'priority' => -100,  | 
            ||
| 171 | ));  | 
            ||
| 172 | }  | 
            ||
| 173 | |||
| 198 | 
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: