Conditions | 1 |
Paths | 1 |
Total Lines | 245 |
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 |
||
24 | public function testTel() |
||
25 | { |
||
26 | $rule = new RuleTel; |
||
|
|||
27 | $xml = simplexml_load_string('<form><field name="tel1" plan="NANP" /> |
||
28 | <field name="tel2" plan="ITU-T" /><field name="tel3" plan="EPP" /> |
||
29 | <field name="tel4" /></form>'); |
||
30 | |||
31 | // Test fail conditions NANP. |
||
32 | $this->assertThat( |
||
33 | $rule->test($xml->field[0], 'bogus'), |
||
34 | $this->isFalse(), |
||
35 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
36 | ); |
||
37 | $this->assertThat( |
||
38 | $rule->test($xml->field[0], '123451234512'), |
||
39 | $this->isFalse(), |
||
40 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
41 | ); |
||
42 | $this->assertThat( |
||
43 | $rule->test($xml->field[0], 'anything_5555555555'), |
||
44 | $this->isFalse(), |
||
45 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
46 | ); |
||
47 | $this->assertThat( |
||
48 | $rule->test($xml->field[0], '5555555555_anything'), |
||
49 | $this->isFalse(), |
||
50 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
51 | ); |
||
52 | |||
53 | // Test fail conditions ITU-T. |
||
54 | $this->assertThat( |
||
55 | $rule->test($xml->field[1], 'bogus'), |
||
56 | $this->isFalse(), |
||
57 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
58 | ); |
||
59 | $this->assertThat( |
||
60 | $rule->test($xml->field[1], '123451234512'), |
||
61 | $this->isFalse(), |
||
62 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
63 | ); |
||
64 | $this->assertThat( |
||
65 | $rule->test($xml->field[1], 'anything_5555555555'), |
||
66 | $this->isFalse(), |
||
67 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
68 | ); |
||
69 | $this->assertThat( |
||
70 | $rule->test($xml->field[1], '5555555555_anything'), |
||
71 | $this->isFalse(), |
||
72 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
73 | ); |
||
74 | $this->assertThat( |
||
75 | $rule->test($xml->field[1], '1 2 3 4 5 6 '), |
||
76 | $this->isFalse(), |
||
77 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
78 | ); |
||
79 | $this->assertThat( |
||
80 | $rule->test($xml->field[1], '5552345678'), |
||
81 | $this->isFalse(), |
||
82 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
83 | ); |
||
84 | $this->assertThat( |
||
85 | $rule->test($xml->field[1], 'anything_555.5555555'), |
||
86 | $this->isFalse(), |
||
87 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
88 | ); |
||
89 | $this->assertThat( |
||
90 | $rule->test($xml->field[1], '555.5555555_anything'), |
||
91 | $this->isFalse(), |
||
92 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
93 | ); |
||
94 | |||
95 | // Test fail conditions EPP. |
||
96 | $this->assertThat( |
||
97 | $rule->test($xml->field[2], 'bogus'), |
||
98 | $this->isFalse(), |
||
99 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
100 | ); |
||
101 | $this->assertThat( |
||
102 | $rule->test($xml->field[2], '12345123451234512345'), |
||
103 | $this->isFalse(), |
||
104 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
105 | ); |
||
106 | $this->assertThat( |
||
107 | $rule->test($xml->field[2], '123.1234'), |
||
108 | $this->isFalse(), |
||
109 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
110 | ); |
||
111 | $this->assertThat( |
||
112 | $rule->test($xml->field[2], '23.1234'), |
||
113 | $this->isFalse(), |
||
114 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
115 | ); |
||
116 | $this->assertThat( |
||
117 | $rule->test($xml->field[2], '3.1234'), |
||
118 | $this->isFalse(), |
||
119 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
120 | ); |
||
121 | |||
122 | // Test fail conditions no plan. |
||
123 | $this->assertThat( |
||
124 | $rule->test($xml->field[3], 'bogus'), |
||
125 | $this->isFalse(), |
||
126 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
127 | ); |
||
128 | |||
129 | $this->assertThat( |
||
130 | $rule->test($xml->field[3], 'anything_555.5555555'), |
||
131 | $this->isFalse(), |
||
132 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
133 | ); |
||
134 | $this->assertThat( |
||
135 | $rule->test($xml->field[3], '555.5555555x555_anything'), |
||
136 | $this->isFalse(), |
||
137 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
138 | ); |
||
139 | $this->assertThat( |
||
140 | $rule->test($xml->field[3], '.5555555'), |
||
141 | $this->isTrue(), |
||
142 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
143 | ); |
||
144 | $this->assertThat( |
||
145 | $rule->test($xml->field[3], '555.'), |
||
146 | $this->isFalse(), |
||
147 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
148 | ); |
||
149 | $this->assertThat( |
||
150 | $rule->test($xml->field[3], '1 2 3 4 5 6 '), |
||
151 | $this->isFalse(), |
||
152 | 'Line:' . __LINE__ . ' The rule should fail and return false.' |
||
153 | ); |
||
154 | |||
155 | // Test pass conditions. |
||
156 | // For NANP |
||
157 | $this->assertThat( |
||
158 | $rule->test($xml->field[0], '(555) 234-5678'), |
||
159 | $this->isTrue(), |
||
160 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
161 | ); |
||
162 | $this->assertThat( |
||
163 | $rule->test($xml->field[0], '1-555-234-5678'), |
||
164 | $this->isTrue(), |
||
165 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
166 | ); |
||
167 | $this->assertThat( |
||
168 | $rule->test($xml->field[0], '+1-555-234-5678'), |
||
169 | $this->isTrue(), |
||
170 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
171 | ); |
||
172 | $this->assertThat( |
||
173 | $rule->test($xml->field[0], '555-234-5678'), |
||
174 | $this->isTrue(), |
||
175 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
176 | ); |
||
177 | $this->assertThat( |
||
178 | $rule->test($xml->field[0], '1-555-234-5678'), |
||
179 | $this->isTrue(), |
||
180 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
181 | ); |
||
182 | $this->assertThat( |
||
183 | $rule->test($xml->field[0], '1 555 234 5678'), |
||
184 | $this->isTrue(), |
||
185 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
186 | ); |
||
187 | |||
188 | // For ITU-T |
||
189 | $this->assertThat( |
||
190 | $rule->test($xml->field[1], '+555 234 5678'), |
||
191 | $this->isTrue(), |
||
192 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
193 | ); |
||
194 | $this->assertThat( |
||
195 | $rule->test($xml->field[1], '+123 555 234 5678'), |
||
196 | $this->isTrue(), |
||
197 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
198 | ); |
||
199 | $this->assertThat( |
||
200 | $rule->test($xml->field[1], '+2 52 34 55'), |
||
201 | $this->isTrue(), |
||
202 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
203 | ); |
||
204 | $this->assertThat( |
||
205 | $rule->test($xml->field[1], '+5552345678'), |
||
206 | $this->isTrue(), |
||
207 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
208 | ); |
||
209 | |||
210 | // For EPP |
||
211 | $this->assertThat( |
||
212 | $rule->test($xml->field[2], '+123.1234'), |
||
213 | $this->isTrue(), |
||
214 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
215 | ); |
||
216 | $this->assertThat( |
||
217 | $rule->test($xml->field[2], '+23.1234'), |
||
218 | $this->isTrue(), |
||
219 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
220 | ); |
||
221 | $this->assertThat( |
||
222 | $rule->test($xml->field[2], '+3.1234'), |
||
223 | $this->isTrue(), |
||
224 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
225 | ); |
||
226 | $this->assertThat( |
||
227 | $rule->test($xml->field[2], '+3.1234x555'), |
||
228 | $this->isTrue(), |
||
229 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
230 | ); |
||
231 | |||
232 | // For no plan |
||
233 | $this->assertThat( |
||
234 | $rule->test($xml->field[3], '555 234 5678'), |
||
235 | $this->isTrue(), |
||
236 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
237 | ); |
||
238 | $this->assertThat( |
||
239 | $rule->test($xml->field[3], '+123 555 234 5678'), |
||
240 | $this->isTrue(), |
||
241 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
242 | ); |
||
243 | $this->assertThat( |
||
244 | $rule->test($xml->field[3], '+2 52 34 55'), |
||
245 | $this->isTrue(), |
||
246 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
247 | ); |
||
248 | $this->assertThat( |
||
249 | $rule->test($xml->field[3], '5552345678'), |
||
250 | $this->isTrue(), |
||
251 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
252 | ); |
||
253 | $this->assertThat( |
||
254 | $rule->test($xml->field[3], '+5552345678'), |
||
255 | $this->isTrue(), |
||
256 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
257 | ); |
||
258 | $this->assertThat( |
||
259 | $rule->test($xml->field[3], '1 2 3 4 5 6 7'), |
||
260 | $this->isTrue(), |
||
261 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
262 | ); |
||
263 | $this->assertThat( |
||
264 | $rule->test($xml->field[3], '123451234512'), |
||
265 | $this->isTrue(), |
||
266 | 'Line:' . __LINE__ . ' The rule should pass and return true.' |
||
267 | ); |
||
268 | } |
||
269 | } |
||
270 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.