Conditions | 4 |
Paths | 4 |
Total Lines | 22 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 4.0119 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
33 | 5 | public function isMatch($prompt, $subject, $lineEnding = null) |
|
34 | { |
||
35 | 5 | $responseEnding = "</cw:response>\r\n"; |
|
36 | |||
37 | // Cheap ending check before expensive regex |
||
38 | 5 | if (substr($subject, -1 * strlen($responseEnding)) != $responseEnding) { |
|
39 | return false; |
||
40 | } |
||
41 | |||
42 | 5 | if (!preg_match("/^\r\n<\(len\)>\d{7}<\/\(len\)>\r\n(.*)$/s", $subject, $match)) { |
|
43 | 1 | throw new DomainException('Response is invalid, could not find header'); |
|
44 | } |
||
45 | |||
46 | 4 | $responseText = $match[1]; |
|
47 | |||
48 | // The prompt type determines whether an error is expected or not. |
||
49 | 4 | if ($prompt == $this->promptError xor false !== strpos($responseText, '<cw:error_info>')) { |
|
50 | 2 | return false; |
|
51 | } |
||
52 | |||
53 | 2 | $this->responseText = $responseText; |
|
54 | 2 | return true; |
|
55 | } |
||
73 |