Complex classes like ApollonValidation often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ApollonValidation, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
7 | class ApollonValidation extends Validation |
||
8 | { |
||
9 | /** |
||
10 | * zip |
||
11 | * 郵便番号チェック 1カラム |
||
12 | * |
||
13 | * @access public |
||
14 | * @author hagiwara |
||
15 | * @param string $check |
||
16 | * @return boolean |
||
17 | */ |
||
18 | public static function zip($check) |
||
19 | { |
||
20 | $regex = '/^[0-9]{3}-?[0-9]{4}$/'; |
||
21 | return self::_check($check, $regex); |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * zip1 |
||
26 | * 郵便番号チェック 上3桁 |
||
27 | * |
||
28 | * @access public |
||
29 | * @author hagiwara |
||
30 | * @param string $check |
||
31 | * @return boolean |
||
32 | */ |
||
33 | public static function zip1($check) |
||
34 | { |
||
35 | $regex = '/^[0-9]{3}$/'; |
||
36 | return self::_check($check, $regex); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * zip2 |
||
41 | * 郵便番号チェック 下4桁 |
||
42 | * |
||
43 | * @access public |
||
44 | * @author hagiwara |
||
45 | * @param string $check |
||
46 | * @return boolean |
||
47 | */ |
||
48 | public static function zip2($check) |
||
53 | |||
54 | /** |
||
55 | * 半角英字チェック |
||
56 | * |
||
57 | * @access public |
||
58 | * @author sakuragawa |
||
59 | * @param string $check |
||
60 | * @return boolean |
||
61 | */ |
||
62 | public static function alpha($check) |
||
67 | |||
68 | /** |
||
69 | * numeric |
||
70 | * 数値チェック |
||
71 | * integerなどの上限チェックを同時に行う |
||
72 | * |
||
73 | * @access public |
||
74 | * @author hagiwara |
||
75 | * @param string $check |
||
76 | * @param integer $limit |
||
77 | * @return boolean |
||
78 | */ |
||
79 | public static function numeric($check, $limit = 2147483647) |
||
92 | |||
93 | /** |
||
94 | * naturalNumber |
||
95 | * 数値チェック |
||
96 | * integerなどの上限チェックを同時に行う |
||
97 | * |
||
98 | * @access public |
||
99 | * @author hagiwara |
||
100 | * @param string $check |
||
101 | * @param boolean $allowZero |
||
102 | * @param integer $limit |
||
103 | * @return boolean |
||
104 | */ |
||
105 | public static function naturalNumber($check, $allowZero = false, $limit = 2147483647) |
||
121 | |||
122 | /** |
||
123 | * hiraganaOnly |
||
124 | * 全角ひらがな以外が含まれていればエラーとするバリデーションチェック |
||
125 | * 全角ダッシュ「ー」のみ必要と考えられるので追加 |
||
126 | * Japanese HIRAGANA Validation |
||
127 | * @param string $check |
||
128 | * @return boolean |
||
129 | * https://github.com/ichikaway/cakeplus |
||
130 | */ |
||
131 | public static function hiraganaOnly($check) |
||
136 | |||
137 | /** |
||
138 | * hiraganaSpaceOnly |
||
139 | * 全角ひらがな以外に全角スペースもOKとするバリデーション |
||
140 | * |
||
141 | * @param string $check |
||
142 | * @return boolean |
||
143 | */ |
||
144 | public static function hiraganaSpaceOnly($check) |
||
149 | |||
150 | /** |
||
151 | * hiraganaAllSpaceOnly |
||
152 | * 全角ひらがな以外に全半角スペースもOKとするバリデーション |
||
153 | * |
||
154 | * @param string $check |
||
155 | * @return boolean |
||
156 | */ |
||
157 | public static function hiraganaAllSpaceOnly($check) |
||
162 | |||
163 | /** |
||
164 | * katakanaOnly |
||
165 | * 全角カタカナ以外が含まれていればエラーとするバリデーションチェック |
||
166 | * Japanese KATAKANA Validation |
||
167 | * |
||
168 | * @param string $check |
||
169 | * @return boolean |
||
170 | * https://github.com/ichikaway/cakeplus |
||
171 | */ |
||
172 | public static function katakanaOnly($check) |
||
179 | |||
180 | /** |
||
181 | * katakanaSpaceOnly |
||
182 | * 全角カタナカ以外に全角スペースもOKとするバリデーション |
||
183 | * |
||
184 | * @param string $check |
||
185 | * @return boolean |
||
186 | */ |
||
187 | public static function katakanaSpaceOnly($check) |
||
192 | |||
193 | /** |
||
194 | * katakanaAllSpaceOnly |
||
195 | * 全角カタナカ以外に全半角スペースもOKとするバリデーション |
||
196 | * |
||
197 | * @param string $check |
||
198 | * @return boolean |
||
199 | */ |
||
200 | public static function katakanaAllSpaceOnly($check) |
||
205 | |||
206 | /** |
||
207 | * zenkakuOnly |
||
208 | * マルチバイト文字以外が含まれていればエラーとするバリデーションチェック |
||
209 | * Japanese ZENKAKU Validation |
||
210 | * |
||
211 | * @param string $check |
||
212 | * @return boolean |
||
213 | * https://github.com/ichikaway/cakeplus |
||
214 | */ |
||
215 | public static function zenkakuOnly($check) |
||
220 | |||
221 | /** |
||
222 | * spaceOnly |
||
223 | * 全角、半角スペースのみであればエラーとするバリデーションチェック |
||
224 | * Japanese Space only validation |
||
225 | * |
||
226 | * @param string $check |
||
227 | * @return boolean |
||
228 | * https://github.com/ichikaway/cakeplus |
||
229 | */ |
||
230 | public static function spaceOnly($check) |
||
235 | |||
236 | /** |
||
237 | * hankakukatakanaOnly |
||
238 | * 半角カタカナ以外が含まれていればエラーとするバリデーションチェック |
||
239 | * Japanese HANKAKU KATAKANA Validation |
||
240 | * http://ash.jp/code/unitbl1.htm |
||
241 | * @param string $check |
||
242 | * @return boolean |
||
243 | */ |
||
244 | public static function hankakukatakanaOnly($check) |
||
249 | |||
250 | /** |
||
251 | * hankakukatakanaSpaceOnly |
||
252 | * 半角カタカナ以外にも半角スペースもOKとするバリデーション |
||
253 | * Japanese HANKAKU KATAKANA SPACE Validation |
||
254 | * http://ash.jp/code/unitbl1.htm |
||
255 | * @param string $check |
||
256 | * @return boolean |
||
257 | */ |
||
258 | public static function hankakukatakanaSpaceOnly($check) |
||
263 | |||
264 | /** |
||
265 | * phone |
||
266 | * |
||
267 | * @access public |
||
268 | * @author hayasaki |
||
269 | * @param string $check |
||
270 | * @return boolean |
||
271 | */ |
||
272 | public static function phone($check) |
||
277 | |||
278 | /** |
||
279 | * phone1 |
||
280 | * 市外局番範囲は2~5桁 |
||
281 | * |
||
282 | * @access public |
||
283 | * @author hayasaki |
||
284 | * @param string $check |
||
285 | * @return boolean |
||
286 | */ |
||
287 | public static function phone1($check) |
||
292 | |||
293 | /** |
||
294 | * phone2 |
||
295 | * 範囲は2~4桁 |
||
296 | * |
||
297 | * @access public |
||
298 | * @author hayasaki |
||
299 | * @param string $check |
||
300 | * @return boolean |
||
301 | */ |
||
302 | public static function phone2($check) |
||
307 | |||
308 | /** |
||
309 | * phone3 |
||
310 | * 範囲は4桁固定 |
||
311 | * |
||
312 | * @access public |
||
313 | * @author hayasaki |
||
314 | * @param string $check |
||
315 | * @return boolean |
||
316 | */ |
||
317 | public static function phone3($check) |
||
322 | |||
323 | /** |
||
324 | * emailNonRfc |
||
325 | * メールアドレスチェック(RFC非準拠) |
||
326 | * |
||
327 | * @access public |
||
328 | * @author fantasista21jp |
||
329 | * @param string $check |
||
330 | * @return boolean |
||
331 | */ |
||
332 | public static function emailNonRfc($check) |
||
337 | |||
338 | /** |
||
339 | * datetimeComparison |
||
340 | * 日時比較チェック |
||
341 | * |
||
342 | * @access public |
||
343 | * @author fantasista21jp |
||
344 | * @param $check1 |
||
345 | * @param $operator |
||
346 | * @param $check2 |
||
347 | * @param $context |
||
348 | * @return boolean |
||
349 | */ |
||
350 | public static function datetimeComparison($check1, $operator, $check2, $context) |
||
407 | } |
||
408 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.