| Conditions | 1 |
| Paths | 1 |
| Total Lines | 82 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 2 |
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 |
||
| 10 | public function __construct() |
||
| 11 | { |
||
| 12 | parent::__construct(); |
||
| 13 | |||
| 14 | $this->add(array( |
||
| 15 | 'name' => 'username', |
||
| 16 | 'options' => array( |
||
| 17 | 'label' => 'Username', |
||
| 18 | ), |
||
| 19 | 'attributes' => array( |
||
| 20 | 'type' => 'text' |
||
| 21 | ), |
||
| 22 | )); |
||
| 23 | |||
| 24 | $this->add(array( |
||
| 25 | 'name' => 'email', |
||
| 26 | 'options' => array( |
||
| 27 | 'label' => 'Email', |
||
| 28 | ), |
||
| 29 | 'attributes' => array( |
||
| 30 | 'type' => 'text' |
||
| 31 | ), |
||
| 32 | )); |
||
| 33 | |||
| 34 | $this->add(array( |
||
| 35 | 'name' => 'display_name', |
||
| 36 | 'options' => array( |
||
| 37 | 'label' => 'Display Name', |
||
| 38 | ), |
||
| 39 | 'attributes' => array( |
||
| 40 | 'type' => 'text' |
||
| 41 | ), |
||
| 42 | )); |
||
| 43 | |||
| 44 | $this->add(array( |
||
| 45 | 'name' => 'password', |
||
| 46 | 'type' => 'password', |
||
| 47 | 'options' => array( |
||
| 48 | 'label' => 'Password', |
||
| 49 | ), |
||
| 50 | 'attributes' => array( |
||
| 51 | 'type' => 'password' |
||
| 52 | ), |
||
| 53 | )); |
||
| 54 | |||
| 55 | $this->add(array( |
||
| 56 | 'name' => 'passwordVerify', |
||
| 57 | 'type' => 'password', |
||
| 58 | 'options' => array( |
||
| 59 | 'label' => 'Password Verify', |
||
| 60 | ), |
||
| 61 | 'attributes' => array( |
||
| 62 | 'type' => 'password' |
||
| 63 | ), |
||
| 64 | )); |
||
| 65 | |||
| 66 | $submitElement = new Element\Button('submit'); |
||
| 67 | $submitElement |
||
| 68 | ->setLabel('Submit') |
||
| 69 | ->setAttributes(array( |
||
| 70 | 'type' => 'submit', |
||
| 71 | )); |
||
| 72 | |||
| 73 | $this->add($submitElement, array( |
||
| 74 | 'priority' => -100, |
||
| 75 | )); |
||
| 76 | |||
| 77 | $this->add(array( |
||
| 78 | 'name' => 'userId', |
||
| 79 | 'type' => 'Zend\Form\Element\Hidden', |
||
| 80 | 'attributes' => array( |
||
| 81 | 'type' => 'hidden' |
||
| 82 | ), |
||
| 83 | )); |
||
| 84 | |||
| 85 | // @TODO: Fix this... getValidator() is a protected method. |
||
| 86 | //$csrf = new Element\Csrf('csrf'); |
||
| 87 | //$csrf->getValidator()->setTimeout($this->getRegistrationOptions()->getUserFormTimeout()); |
||
| 88 | //$this->add($csrf); |
||
| 89 | |||
| 90 | $this->getEventManager()->trigger('init', $this); |
||
| 91 | } |
||
| 92 | |||
| 97 |