Conditions | 1 |
Paths | 1 |
Total Lines | 111 |
Code Lines | 73 |
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 |
||
64 | public function init() |
||
65 | { |
||
66 | $this->setName('contact'); |
||
67 | |||
68 | $this->setHydrator(new ArraySerializable); |
||
69 | |||
70 | $this->add(array( |
||
71 | 'name' => 'from', |
||
72 | 'type' => 'Zend\Form\Element\Text', |
||
73 | 'options' => array( |
||
74 | 'label' => 'From:', |
||
75 | 'required' => true, |
||
76 | 'validators' => array( |
||
77 | array( |
||
78 | 'name' => 'EmailAddress', |
||
79 | 'options' => array( |
||
80 | 'allow' => HostnameValidator::ALLOW_DNS, |
||
81 | 'domain' => true, |
||
82 | ), |
||
83 | ), |
||
84 | ), |
||
85 | ) |
||
86 | )); |
||
87 | |||
88 | $this->add(array( |
||
89 | 'name' => 'subject', |
||
90 | 'type' => 'Zend\Form\Element\Text', |
||
91 | 'options' => array( |
||
92 | 'label' => 'Subject:', |
||
93 | 'required' => true, |
||
94 | 'filters' => array( |
||
95 | 'StripTags', |
||
96 | ), |
||
97 | 'validators' => array( |
||
98 | array('StringLength', true, array( |
||
99 | 'encoding' => 'UTF-8', |
||
100 | 'min' => 2, |
||
101 | 'max' => 140, |
||
102 | )), |
||
103 | ) |
||
104 | ), |
||
105 | )); |
||
106 | |||
107 | $this->add(array( |
||
108 | 'name' => 'body', |
||
109 | 'type' => 'Zend\Form\Element\Textarea', |
||
110 | 'options' => array( |
||
111 | 'label' => 'Your message:', |
||
112 | 'required' => true, |
||
113 | 'cols' => 80, |
||
114 | 'rows' => 10, |
||
115 | ) |
||
116 | )); |
||
117 | |||
118 | $this->add(array( |
||
119 | 'name' => 'country', |
||
120 | 'type' => 'Zend\Form\Element\Text', |
||
121 | 'options' => array( |
||
122 | 'value' => '', |
||
123 | 'class' => 'zonkos', |
||
124 | 'label' => 'SPAM-Protection: Please leave this field as it is!', |
||
125 | ), |
||
126 | )); |
||
127 | |||
128 | $this->add(new Element\Csrf('csrf')); |
||
129 | |||
130 | $this->add(array( |
||
131 | 'name' => 'Send', |
||
132 | 'type' => 'Zend\Form\Element\Submit', |
||
133 | 'attributes' => array( |
||
134 | 'value' => 'Send' |
||
135 | ) |
||
136 | )); |
||
137 | |||
138 | |||
139 | $from = new Input('from'); |
||
140 | $from->setRequired(true); |
||
141 | $from->getValidatorChain() |
||
142 | ->attach(new NotEmpty()) |
||
143 | ->attach(new EmailAddress()) |
||
144 | ; |
||
145 | |||
146 | $country = new Input('country'); |
||
147 | $country->setAllowEmpty(true); |
||
|
|||
148 | $country->getValidatorChain() |
||
149 | ->attach(new Identical('')) |
||
150 | ; |
||
151 | |||
152 | $subject = new Input('subject'); |
||
153 | $subject->setRequired(true); |
||
154 | $subject->getValidatorChain() |
||
155 | ->attach(new NotEmpty()) |
||
156 | ; |
||
157 | |||
158 | $body = new Input('body'); |
||
159 | $body->setRequired(true); |
||
160 | $body->getValidatorChain() |
||
161 | ->attach(new NotEmpty()) |
||
162 | ; |
||
163 | |||
164 | $filter = new InputFilter(); |
||
165 | $filter->add($from); |
||
166 | $filter->add($subject); |
||
167 | $filter->add($body); |
||
168 | $filter->add($country); |
||
169 | |||
170 | $this->setInputFilter($filter); |
||
171 | |||
172 | |||
173 | return $this; |
||
174 | } |
||
175 | } |
||
176 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.