Conditions | 12 |
Paths | 130 |
Total Lines | 49 |
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 |
||
48 | public function test(SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null) |
||
49 | { |
||
50 | // If the field is empty and not required, the field is valid. |
||
51 | $required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required'); |
||
52 | |||
53 | if (!$required && empty($value)) |
||
54 | { |
||
55 | return true; |
||
56 | } |
||
57 | |||
58 | // If the tld attribute is present, change the regular expression to require at least 2 characters for it. |
||
59 | $tld = ((string) $element['tld'] == 'tld' || (string) $element['tld'] == 'required'); |
||
60 | |||
61 | if ($tld) |
||
62 | { |
||
63 | $this->regex = '^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])' |
||
64 | . '?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$'; |
||
65 | } |
||
66 | |||
67 | // Determine if the multiple attribute is present |
||
68 | $multiple = ((string) $element['multiple'] == 'true' || (string) $element['multiple'] == 'multiple'); |
||
69 | |||
70 | if ($multiple) |
||
71 | { |
||
72 | $values = explode(',', $value); |
||
73 | } |
||
74 | |||
75 | if (!$multiple) |
||
76 | { |
||
77 | // Test the value against the regular expression. |
||
78 | if (!parent::test($element, $value, $group, $input, $form)) |
||
79 | { |
||
80 | return false; |
||
81 | } |
||
82 | } |
||
83 | else |
||
84 | { |
||
85 | foreach ($values as $value) |
||
86 | { |
||
87 | // Test the value against the regular expression. |
||
88 | if (!parent::test($element, $value, $group, $input, $form)) |
||
89 | { |
||
90 | return false; |
||
91 | } |
||
92 | } |
||
93 | } |
||
94 | |||
95 | return true; |
||
96 | } |
||
97 | } |
||
98 |
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.