TokenParser   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 24
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parseVerifier() 0 10 2
A parseAuthenticityToken() 0 10 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 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