Conditions | 14 |
Paths | 22 |
Total Lines | 69 |
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 |
||
39 | public function test(SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null) |
||
40 | { |
||
41 | // If the field is empty and not required, the field is valid. |
||
42 | $required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required'); |
||
43 | |||
44 | if (!$required && empty($value)) |
||
45 | { |
||
46 | return true; |
||
47 | } |
||
48 | |||
49 | /* |
||
50 | * @see http://www.nanpa.com/ |
||
51 | * @see http://tools.ietf.org/html/rfc4933 |
||
52 | * @see http://www.itu.int/rec/T-REC-E.164/en |
||
53 | * |
||
54 | * Regex by Steve Levithan |
||
55 | * @see http://blog.stevenlevithan.com/archives/validate-phone-number |
||
56 | * @note that valid ITU-T and EPP must begin with +. |
||
57 | */ |
||
58 | $regexarray = array('NANP' => '/^(?:\+?1[-. ]?)?\(?([2-9][0-8][0-9])\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$/', |
||
59 | 'ITU-T' => '/^\+(?:[0-9] ?){6,14}[0-9]$/', 'EPP' => '/^\+[0-9]{1,3}\.[0-9]{4,14}(?:x.+)?$/'); |
||
60 | |||
61 | if (isset($element['plan'])) |
||
62 | { |
||
63 | $plan = (string) $element['plan']; |
||
64 | |||
65 | if ($plan == 'northamerica' || $plan == 'us') |
||
66 | { |
||
67 | $plan = 'NANP'; |
||
68 | } |
||
69 | elseif ($plan == 'International' || $plan == 'int' || $plan == 'missdn' || !$plan) |
||
70 | { |
||
71 | $plan = 'ITU-T'; |
||
72 | } |
||
73 | elseif ($plan == 'IETF') |
||
74 | { |
||
75 | $plan = 'EPP'; |
||
76 | } |
||
77 | |||
78 | $regex = $regexarray[$plan]; |
||
79 | |||
80 | // Test the value against the regular expression. |
||
81 | if (preg_match($regex, $value) == false) |
||
82 | { |
||
83 | return false; |
||
84 | } |
||
85 | } |
||
86 | else |
||
87 | { |
||
88 | /* |
||
89 | * If the rule is set but no plan is selected just check that there are between |
||
90 | * 7 and 15 digits inclusive and no illegal characters (but common number separators |
||
91 | * are allowed). |
||
92 | */ |
||
93 | $cleanvalue = preg_replace('/[+. \-(\)]/', '', $value); |
||
94 | $regex = '/^[0-9]{7,15}?$/'; |
||
95 | |||
96 | if (preg_match($regex, $cleanvalue) == true) |
||
97 | { |
||
98 | return true; |
||
99 | } |
||
100 | else |
||
101 | { |
||
102 | return false; |
||
103 | } |
||
104 | } |
||
105 | |||
106 | return true; |
||
107 | } |
||
108 | } |
||
109 |
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.