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

TokenParser   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 26
ccs 14
cts 14
cp 1
rs 10

2 Methods

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