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   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 60
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 60
ccs 26
cts 27
cp 0.963
rs 10
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 3 1
A of() 0 3 1
A matches() 0 9 2
A __construct() 0 7 2
A capture() 0 22 3
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