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 — develop ( 3d4c79...7ab88f )
by Baptiste
05:30
created

RegExp   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Test Coverage

Coverage 96.3%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 23
c 1
b 0
f 1
dl 0
loc 66
ccs 26
cts 27
cp 0.963
rs 10
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A of() 0 3 1
A __construct() 0 7 2
A capture() 0 23 3
A matches() 0 9 2
A toString() 0 3 1
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
    /**
30
     * @throws RegexException
31
     */
32 3
    public function matches(Str $string): bool
33
    {
34 3
        $value = \preg_match($this->pattern, $string->toString());
35
36 3
        if ($value === false) {
37 1
            throw new RegexException('', \preg_last_error());
38
        }
39
40 2
        return (bool) $value;
41
    }
42
43
44
    /**
45
     * @throws RegexException
46
     *
47
     * @return Map<scalar, Str>
48
     */
49 4
    public function capture(Str $string): Map
50
    {
51 4
        $matches = [];
52 4
        $value = \preg_match($this->pattern, $string->toString(), $matches);
53
54 4
        if ($value === false) {
55 1
            throw new RegexException('', \preg_last_error());
56
        }
57
58
        /** @var Map<scalar, Str> */
59 3
        $map = Map::of('scalar', Str::class);
60
61 3
        foreach ($matches as $key => $match) {
62 3
            $map = ($map)(
63 3
                $key,
64
                Str::of(
65 3
                    (string) $match,
66 3
                    $string->encoding()->toString()
67
                )
68
            );
69
        }
70
71 3
        return $map;
72
    }
73
74 2
    public function toString(): string
75
    {
76 2
        return $this->pattern;
77
    }
78
}
79