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