Completed
Push — master ( 458684...f006a2 )
by Ryosuke
02:58
created

RegexParser::parseVerifier()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 9

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