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.
Passed
Push — master ( f46a23...825633 )
by Baptiste
04:48
created

RegExp::capture()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 3
nop 1
dl 0
loc 22
ccs 13
cts 13
cp 1
crap 3
rs 9.8666
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Immutable;
5
6
use Innmind\Immutable\Exception\{
7
    DomainException,
8
    RegexException
9
};
10
11
final class RegExp
12
{
13
    private $pattern;
14
15 20
    public function __construct(string $pattern)
16
    {
17 20
        if (@\preg_match($pattern, '') === false) {
18 2
            throw new DomainException($pattern, \preg_last_error());
19
        }
20
21 18
        $this->pattern = $pattern;
22 18
    }
23
24 12
    public static function of(string $pattern): self
25
    {
26 12
        return new self($pattern);
27
    }
28
29 6
    public function matches(Str $string): bool
30
    {
31 6
        $value = \preg_match($this->pattern, (string) $string);
32
33 6
        if ($value === false) {
34 2
            throw new RegexException('', \preg_last_error());
35
        }
36
37 4
        return (bool) $value;
38
    }
39
40
41
    /**
42
     * @return MapInterface<scalar, Str>
43
     */
44 8
    public function capture(Str $string): MapInterface
45
    {
46 8
        $matches = [];
47 8
        $value = \preg_match($this->pattern, (string) $string, $matches);
48
49 8
        if ($value === false) {
50 2
            throw new RegexException('', \preg_last_error());
51
        }
52
53 6
        $map = new Map('scalar', Str::class);
54
55 6
        foreach ($matches as $key => $match) {
56 6
            $map = $map->put(
57 6
                $key,
58 6
                new Str(
59 6
                    (string) $match,
60 6
                    (string) $string->encoding()
61
                )
62
            );
63
        }
64
65 6
        return $map;
66
    }
67
68 4
    public function __toString(): string
69
    {
70 4
        return $this->pattern;
71
    }
72
}
73