Conditions | 22 |
Paths | 22 |
Total Lines | 44 |
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 |
||
29 | public function getValidator( $scheme ) { |
||
30 | switch ( $scheme ) { |
||
31 | // Schemes with "://", copied from $wgUrlProtocols in MediaWiki's DefaultSettings.php |
||
32 | case 'ftp': |
||
33 | case 'ftps': |
||
34 | case 'git': |
||
35 | case 'gopher': |
||
36 | case 'http': |
||
37 | case 'https': |
||
38 | case 'irc': |
||
39 | case 'ircs': |
||
40 | case 'mms': |
||
41 | case 'nntp': |
||
42 | case 'redis': |
||
43 | case 'sftp': |
||
44 | case 'ssh': |
||
45 | case 'svn': |
||
46 | case 'telnet': |
||
47 | case 'worldwind': |
||
48 | |||
49 | // Additional VCS schemes not supported by MediaWiki. "bzr" is GNU Bazaar from Canonical |
||
50 | // Ltd. See https://phabricator.wikimedia.org/T146692 |
||
51 | case 'bzr': |
||
52 | case 'cvs': |
||
53 | $regex = '!^' . preg_quote( $scheme, '!' ) . '://(' . Parser::EXT_LINK_URL_CLASS |
||
54 | . ')+\z!ui'; |
||
55 | break; |
||
56 | |||
57 | case 'mailto': |
||
58 | $regex = '!^mailto:(' . Parser::EXT_LINK_URL_CLASS . ')+@(' |
||
59 | . Parser::EXT_LINK_URL_CLASS . ')+\z!ui'; |
||
60 | break; |
||
61 | |||
62 | case '*': |
||
63 | case 'any': |
||
64 | $regex = '!^([a-z][a-z\d+.-]*):(' . Parser::EXT_LINK_URL_CLASS . ')+\z!ui'; |
||
65 | break; |
||
66 | |||
67 | default: |
||
68 | return null; |
||
69 | } |
||
70 | |||
71 | return new RegexValidator( $regex, false, 'bad-url' ); |
||
72 | } |
||
73 | |||
98 |