TokenParser::parseVerifier()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 10
ccs 8
cts 8
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace mpyw\Cowitter\Helpers;
4
5
use mpyw\Cowitter\ResponseInterface;
6
use mpyw\Cowitter\HttpException;
7
8
class TokenParser
9
{
10 6
    public static function parseAuthenticityToken(ResponseInterface $response) {
11 6
        static $pattern = '@<input name="authenticity_token" type="hidden" value="([^"]++)">@';
12 6
        if (!preg_match($pattern, $response->getRawContent(), $matches)) {
13 1
            throw new HttpException(
14 1
                'Failed to get authenticity_token.',
15 1
                -1,
16 1
                $response
17
            );
18
        }
19 5
        return $matches[1];
20
    }
21
22 6
    public static function parseVerifier(ResponseInterface $response) {
23 6
        static $pattern = '@<code>([^<]++)</code>@';
24 6
        if (!preg_match($pattern, $response->getRawContent(), $matches)) {
25 3
            throw new HttpException(
26 3
                'Wrong username or password. Otherwise, you may have to verify your email address.',
27 3
                -1,
28 3
                $response
29
            );
30
        }
31 3
        return $matches[1];
32
    }
33
}
34