Conditions | 16 |
Paths | 30 |
Total Lines | 69 |
Lines | 8 |
Ratio | 11.59 % |
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 |
||
43 | public function test(SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null) |
||
44 | { |
||
45 | // If the field is empty and not required, the field is valid. |
||
46 | $required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required'); |
||
47 | |||
48 | if (!$required && empty($value)) |
||
49 | { |
||
50 | return true; |
||
51 | } |
||
52 | |||
53 | $urlParts = UriHelper::parse_url($value); |
||
54 | |||
55 | // See http://www.w3.org/Addressing/URL/url-spec.txt |
||
56 | // Use the full list or optionally specify a list of permitted schemes. |
||
57 | if ($element['schemes'] == '') |
||
58 | { |
||
59 | $scheme = array('http', 'https', 'ftp', 'ftps', 'gopher', 'mailto', 'news', 'prospero', 'telnet', 'rlogin', 'tn3270', 'wais', 'url', |
||
60 | 'mid', 'cid', 'nntp', 'tel', 'urn', 'ldap', 'file', 'fax', 'modem', 'git'); |
||
61 | } |
||
62 | else |
||
63 | { |
||
64 | $scheme = explode(',', $element['schemes']); |
||
65 | } |
||
66 | |||
67 | /* |
||
68 | * This rule is only for full URLs with schemes because parse_url does not parse |
||
69 | * accurately without a scheme. |
||
70 | * @see http://php.net/manual/en/function.parse-url.php |
||
71 | */ |
||
72 | if ($urlParts && !array_key_exists('scheme', $urlParts)) |
||
73 | { |
||
74 | return false; |
||
75 | } |
||
76 | |||
77 | $urlScheme = (string) $urlParts['scheme']; |
||
78 | $urlScheme = strtolower($urlScheme); |
||
79 | |||
80 | if (in_array($urlScheme, $scheme) == false) |
||
81 | { |
||
82 | return false; |
||
83 | } |
||
84 | |||
85 | // For some schemes here must be two slashes. |
||
86 | $scheme = array('http', 'https', 'ftp', 'ftps', 'gopher', 'wais', 'prospero', 'sftp', 'telnet', 'git'); |
||
87 | |||
88 | if (in_array($urlScheme, $scheme) && substr($value, strlen($urlScheme), 3) !== '://') |
||
89 | { |
||
90 | return false; |
||
91 | } |
||
92 | |||
93 | // The best we can do for the rest is make sure that the strings are valid UTF-8 |
||
94 | // and the port is an integer. |
||
95 | View Code Duplication | if (array_key_exists('host', $urlParts) && !StringHelper::valid((string) $urlParts['host'])) |
|
96 | { |
||
97 | return false; |
||
98 | } |
||
99 | |||
100 | if (array_key_exists('port', $urlParts) && !is_int((int) $urlParts['port'])) |
||
101 | { |
||
102 | return false; |
||
103 | } |
||
104 | |||
105 | View Code Duplication | if (array_key_exists('path', $urlParts) && !StringHelper::valid((string) $urlParts['path'])) |
|
106 | { |
||
107 | return false; |
||
108 | } |
||
109 | |||
110 | return true; |
||
111 | } |
||
112 | } |
||
113 |
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.