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 — develop ( 870d79...a1e45f )
by Baptiste
05:29
created

RegExp::of()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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