Conditions | 5 |
Paths | 12 |
Total Lines | 24 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
29 | public function validate(HTTPRequest $request) |
||
30 | { |
||
31 | $fieldname = $request->getVar('field') ? $request->getVar('field') : 'number'; |
||
32 | $rawNumber = $request->getVar($fieldname); |
||
33 | // as a fallback solution, we get the first $_GET parameter |
||
34 | if (!$rawNumber) { |
||
35 | $qs = array_values($_GET); |
||
36 | array_shift($qs); //remove first that is always url |
||
37 | $rawNumber = array_shift($qs); |
||
38 | } |
||
39 | $country = $request->getVar('country'); |
||
40 | try { |
||
41 | $result = PhoneHelper::validatePhoneNumber( |
||
42 | $rawNumber, |
||
43 | $country |
||
44 | ); |
||
45 | if ($result) { |
||
46 | return 1; |
||
47 | } |
||
48 | } catch (Exception $e) { |
||
49 | // Not valid |
||
50 | } |
||
51 | $this->getResponse()->setStatusCode(400); |
||
52 | return 0; |
||
53 | } |
||
76 |