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

RegexParser   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
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 28
ccs 14
cts 14
cp 1
rs 10

2 Methods

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