Passed
Push — master ( 48ce4d...e85b61 )
by Ryosuke
03:52
created

TokenParser::parseVerifier()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
crap 2
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
                $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
                $response
29
            );
30
        }
31 3
        return $matches[1];
32
    }
33
}
34