Conditions | 1 |
Paths | 1 |
Total Lines | 238 |
Code Lines | 195 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
53 | public function contactsProvider() { |
||
54 | return array( |
||
55 | array( |
||
56 | array( |
||
57 | 'foo' |
||
58 | ), |
||
59 | array( |
||
60 | 0 => array( |
||
61 | 'id' => 'foo', |
||
62 | 'FN' => 'foo', |
||
63 | 'EMAIL' => array(), |
||
64 | 'IMPP' => array( |
||
65 | 0 => 'x-owncloud-handle:foo', |
||
66 | ), |
||
67 | 'addressbook-key' => 'local', |
||
68 | ), |
||
69 | 1 => array( |
||
70 | 'id' => 'bar', |
||
71 | 'FN' => 'bar', |
||
72 | 'EMAIL' => array(), |
||
73 | 'IMPP' => array( |
||
74 | 0 => 'x-owncloud-handle:bar', |
||
75 | ), |
||
76 | 'addressbook-key' => 'local', |
||
77 | ), |
||
78 | 2 => array( |
||
79 | 'id' => '1', |
||
80 | 'N' => array( |
||
81 | 0 => '', |
||
82 | 1 => 'TestContact', |
||
83 | 2 => '', |
||
84 | 3 => '', |
||
85 | 4 => '', |
||
86 | ), |
||
87 | 'UID' => '1a2a30d7-4907-4d5c-8e4a-3e51cf89e55a@localhost', |
||
88 | 'FN' => 'TestContact', |
||
89 | 'addressbook-key' => 'local:1', |
||
90 | ) |
||
91 | ), |
||
92 | array( |
||
93 | 'contacts' => |
||
94 | array( |
||
95 | 0 => |
||
96 | array( |
||
97 | 'id' => 'foo', |
||
98 | 'online' => true, |
||
99 | 'displayname' => 'foo', |
||
100 | 'order' => 1, |
||
101 | 'saved' => true, |
||
102 | 'backends' => |
||
103 | array( |
||
104 | 0 => |
||
105 | array( |
||
106 | 'id' => 'email', |
||
107 | 'displayname' => 'E-mail', |
||
108 | 'protocol' => 'email', |
||
109 | 'namespace' => ' email', |
||
110 | 'value' => |
||
111 | array( |
||
112 | 0 => |
||
113 | array(), |
||
114 | ), |
||
115 | ), |
||
116 | 1 => |
||
117 | array( |
||
118 | 'id' => 'och', |
||
119 | 'displayname' => 'ownCloud Chat', |
||
120 | 'protocol' => 'x-owncloud-handle', |
||
121 | 'namespace' => 'och', |
||
122 | 'value' => 'foo', |
||
123 | ), |
||
124 | ), |
||
125 | 'address_book_id' => '', |
||
126 | 'address_book_backend' => 'local', |
||
127 | ), |
||
128 | 1 => |
||
129 | array( |
||
130 | 'id' => 'bar', |
||
131 | 'online' => false, |
||
132 | 'displayname' => 'bar', |
||
133 | 'order' => 2, |
||
134 | 'saved' => true, |
||
135 | 'backends' => |
||
136 | array( |
||
137 | 0 => |
||
138 | array( |
||
139 | 'id' => 'email', |
||
140 | 'displayname' => 'E-mail', |
||
141 | 'protocol' => 'email', |
||
142 | 'namespace' => ' email', |
||
143 | 'value' => |
||
144 | array( |
||
145 | 0 => |
||
146 | array(), |
||
147 | ), |
||
148 | ), |
||
149 | 1 => |
||
150 | array( |
||
151 | 'id' => 'och', |
||
152 | 'displayname' => 'ownCloud Chat', |
||
153 | 'protocol' => 'x-owncloud-handle', |
||
154 | 'namespace' => 'och', |
||
155 | 'value' => 'bar', |
||
156 | ), |
||
157 | ), |
||
158 | 'address_book_id' => '', |
||
159 | 'address_book_backend' => 'local', |
||
160 | ), |
||
161 | 2 => |
||
162 | array( |
||
163 | 'id' => '1', |
||
164 | 'online' => false, |
||
165 | 'displayname' => 'TestContact', |
||
166 | 'order' => 3, |
||
167 | 'saved' => true, |
||
168 | 'backends' => |
||
169 | array( |
||
170 | 0 => |
||
171 | array( |
||
172 | 'id' => 'email', |
||
173 | 'displayname' => 'E-mail', |
||
174 | 'protocol' => 'email', |
||
175 | 'namespace' => ' email', |
||
176 | 'value' => |
||
177 | array( |
||
178 | 0 => |
||
179 | array(), |
||
180 | ), |
||
181 | ), |
||
182 | ), |
||
183 | 'address_book_id' => '1', |
||
184 | 'address_book_backend' => 'local', |
||
185 | ), |
||
186 | ), |
||
187 | 'contactsList' => |
||
188 | array( |
||
189 | 0 => 'foo', |
||
190 | 1 => 'bar', |
||
191 | 2 => '1', |
||
192 | ), |
||
193 | 'contactsObj' => |
||
194 | array( |
||
195 | 'foo' => |
||
196 | array( |
||
197 | 'id' => 'foo', |
||
198 | 'online' => true, |
||
199 | 'displayname' => 'foo', |
||
200 | 'order' => 1, |
||
201 | 'saved' => true, |
||
202 | 'backends' => |
||
203 | array( |
||
204 | 0 => |
||
205 | array( |
||
206 | 'id' => 'email', |
||
207 | 'displayname' => 'E-mail', |
||
208 | 'protocol' => 'email', |
||
209 | 'namespace' => ' email', |
||
210 | 'value' => |
||
211 | array( |
||
212 | 0 => |
||
213 | array(), |
||
214 | ), |
||
215 | ), |
||
216 | 1 => |
||
217 | array( |
||
218 | 'id' => 'och', |
||
219 | 'displayname' => 'ownCloud Chat', |
||
220 | 'protocol' => 'x-owncloud-handle', |
||
221 | 'namespace' => 'och', |
||
222 | 'value' => 'foo', |
||
223 | ), |
||
224 | ), |
||
225 | 'address_book_id' => '', |
||
226 | 'address_book_backend' => 'local', |
||
227 | ), |
||
228 | 'bar' => |
||
229 | array( |
||
230 | 'id' => 'bar', |
||
231 | 'online' => false, |
||
232 | 'displayname' => 'bar', |
||
233 | 'order' => 2, |
||
234 | 'saved' => true, |
||
235 | 'backends' => |
||
236 | array( |
||
237 | 0 => |
||
238 | array( |
||
239 | 'id' => 'email', |
||
240 | 'displayname' => 'E-mail', |
||
241 | 'protocol' => 'email', |
||
242 | 'namespace' => ' email', |
||
243 | 'value' => |
||
244 | array( |
||
245 | 0 => |
||
246 | array(), |
||
247 | ), |
||
248 | ), |
||
249 | 1 => |
||
250 | array( |
||
251 | 'id' => 'och', |
||
252 | 'displayname' => 'ownCloud Chat', |
||
253 | 'protocol' => 'x-owncloud-handle', |
||
254 | 'namespace' => 'och', |
||
255 | 'value' => 'bar', |
||
256 | ), |
||
257 | ), |
||
258 | 'address_book_id' => '', |
||
259 | 'address_book_backend' => 'local', |
||
260 | ), |
||
261 | 1 => |
||
262 | array( |
||
263 | 'id' => '1', |
||
264 | 'online' => false, |
||
265 | 'displayname' => 'TestContact', |
||
266 | 'order' => 3, |
||
267 | 'saved' => true, |
||
268 | 'backends' => |
||
269 | array( |
||
270 | 0 => |
||
271 | array( |
||
272 | 'id' => 'email', |
||
273 | 'displayname' => 'E-mail', |
||
274 | 'protocol' => 'email', |
||
275 | 'namespace' => ' email', |
||
276 | 'value' => |
||
277 | array( |
||
278 | 0 => |
||
279 | array(), |
||
280 | ), |
||
281 | ), |
||
282 | ), |
||
283 | 'address_book_id' => '1', |
||
284 | 'address_book_backend' => 'local', |
||
285 | ), |
||
286 | ), |
||
287 | ) |
||
288 | ) |
||
289 | ); |
||
290 | } |
||
291 | |||
439 | } |
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: