| Conditions | 1 |
| Paths | 1 |
| Total Lines | 118 |
| Code Lines | 76 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 2 |
| 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 |
||
| 22 | public function __construct($name = null) |
||
| 23 | { |
||
| 24 | // we want to ignore the name passed |
||
| 25 | parent::__construct('user'); |
||
| 26 | |||
| 27 | $this->setAttribute('method', 'post'); |
||
| 28 | $this->add( |
||
| 29 | array( |
||
| 30 | 'name' => 'user_id', |
||
| 31 | 'attributes' => array( |
||
| 32 | 'type' => 'hidden', |
||
| 33 | ), |
||
| 34 | ) |
||
| 35 | ); |
||
| 36 | $this->add( |
||
| 37 | array( |
||
| 38 | 'name' => 'username', |
||
| 39 | 'attributes' => array( |
||
| 40 | 'type' => 'text', |
||
| 41 | ), |
||
| 42 | 'options' => array( |
||
| 43 | 'label' => 'user name', |
||
| 44 | ), |
||
| 45 | ) |
||
| 46 | ); |
||
| 47 | $this->add( |
||
| 48 | array( |
||
| 49 | 'name' => 'email', |
||
| 50 | 'attributes' => array( |
||
| 51 | 'type' => 'text', |
||
| 52 | ), |
||
| 53 | 'options' => array( |
||
| 54 | 'label' => 'email', |
||
| 55 | ), |
||
| 56 | ) |
||
| 57 | ); |
||
| 58 | $this->add( |
||
| 59 | array( |
||
| 60 | 'name' => 'display_name', |
||
| 61 | 'attributes' => array( |
||
| 62 | 'type' => 'text', |
||
| 63 | ), |
||
| 64 | 'options' => array( |
||
| 65 | 'label' => 'display name', |
||
| 66 | ), |
||
| 67 | ) |
||
| 68 | ); |
||
| 69 | $this->add( |
||
| 70 | array( |
||
| 71 | 'name' => 'password', |
||
| 72 | 'attributes' => array( |
||
| 73 | 'type' => 'password', |
||
| 74 | ), |
||
| 75 | 'options' => array( |
||
| 76 | 'label' => 'password', |
||
| 77 | ), |
||
| 78 | ) |
||
| 79 | ); |
||
| 80 | $this->add( |
||
| 81 | array( |
||
| 82 | 'name' => 'state', |
||
| 83 | 'type' => 'select', |
||
| 84 | 'attributes' => array( |
||
| 85 | 'type' => 'select', |
||
| 86 | 'options' => array( |
||
| 87 | '1' => 'active', |
||
| 88 | '0' => 'inactive', |
||
| 89 | ), |
||
| 90 | ), |
||
| 91 | 'options' => array( |
||
| 92 | 'label' => 'status', |
||
| 93 | ), |
||
| 94 | ) |
||
| 95 | ); |
||
| 96 | |||
| 97 | $this->add( |
||
| 98 | array( |
||
| 99 | 'name' => 'aclrole', |
||
| 100 | 'type' => 'select', |
||
| 101 | 'attributes' => array( |
||
| 102 | 'type' => 'select', |
||
| 103 | 'options' => array( |
||
| 104 | 'public' => 'no user', |
||
| 105 | 'user' => 'user', |
||
| 106 | 'admin' => 'admin', |
||
| 107 | ), |
||
| 108 | ), |
||
| 109 | 'options' => array( |
||
| 110 | 'label' => 'role', |
||
| 111 | ), |
||
| 112 | ) |
||
| 113 | ); |
||
| 114 | |||
| 115 | |||
| 116 | $this->add( |
||
| 117 | array( |
||
| 118 | 'name' => 'submit', |
||
| 119 | 'attributes' => array( |
||
| 120 | 'type' => 'submit', |
||
| 121 | 'value' => 'save', |
||
| 122 | 'id' => 'submitbutton', |
||
| 123 | ), |
||
| 124 | 'options' => array( |
||
| 125 | 'label' => 'save', |
||
| 126 | ), |
||
| 127 | ) |
||
| 128 | ); |
||
| 129 | |||
| 130 | $this->add( |
||
| 131 | array( |
||
| 132 | 'name' => 'reset', |
||
| 133 | 'attributes' => array( |
||
| 134 | 'type' => 'reset', |
||
| 135 | 'value' => 'reset', |
||
| 136 | 'id' => 'resetbutton', |
||
| 137 | ), |
||
| 138 | 'options' => array( |
||
| 139 | 'label' => 'reset', |
||
| 140 | ), |
||
| 144 | } |