GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( ffad87...ae724f )
by Norbert
03:28
created

MatchRegex::getError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Coduo\PHPMatcher\Matcher\Pattern\Expander;
4
5
use Coduo\PHPMatcher\Matcher\Pattern\PatternExpander;
6
use Coduo\ToString\StringConverter;
7
8
/**
9
 * @author Benjamin Lazarecki <[email protected]>
10
 */
11
class MatchRegex implements PatternExpander
12
{
13
    /**
14
     * @var null|string
15
     */
16
    private $error;
17
18
    /**
19
     * @var string
20
     */
21
    private $pattern;
22
23
    /**
24
     * @param string $pattern
25
     */
26
    public function __construct($pattern)
27
    {
28
        if (!is_string($pattern)) {
29
            throw new \InvalidArgumentException("Regex pattern must be a string.");
30
        }
31
32
        if (!is_string($pattern) || @preg_match($pattern, '') === false) {
33
            throw new \InvalidArgumentException("Regex pattern must be a valid one.");
34
        }
35
36
        $this->pattern = $pattern;
37
    }
38
39
    /**
40
     * @param string $value
41
     *
42
     * @return boolean
43
     */
44
    public function match($value)
45
    {
46
        if (false === is_string($value)) {
47
            $this->error = sprintf("Match expander require \"string\", got \"%s\".", new StringConverter($value));
48
49
            return false;
50
        }
51
52
        if (1 !== preg_match($this->pattern, $value)) {
53
            $this->error = sprintf("string \"%s\" don't match pattern %s.", $value, $this->pattern);
54
55
            return false;
56
        }
57
58
        return true;
59
    }
60
61
    /**
62
     * @return string|null
63
     */
64
    public function getError()
65
    {
66
        return $this->error;
67
    }
68
}
69