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.

CreatesFromPattern::usePattern()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Noodle\Transition;
4
5
use Noodle\State\FlyweightState;
6
use Noodle\Transition\Exception\InvalidPattern;
7
use Noodle\Transition\Exception\TransitionPatternMismatch;
8
use Noodle\Transition\Input\FlyweightInput;
9
10
trait CreatesFromPattern
11
{
12
    /**
13
     * The regex pattern to use for creating Transitions
14
     *
15
     * @var string
16
     */
17
    private static $pattern = "/^(?P<current_state>[^+]+) \+ (?P<input>[^=]+) = (?P<next_state>.+)$/";
18
19
    /**
20
     * {@inheritdoc}
21
     *
22
     * @throws TransitionPatternMismatch
23
     */
24 16
    public static function new(string $transition) : Transition
25
    {
26 16
        $isMatch = preg_match(self::getPattern(), $transition, $matches);
27 16
        $withExpectedNamedCaptures = isset($matches['current_state'], $matches['input'], $matches['next_state']);
28
29 16
        if (!$isMatch || !$withExpectedNamedCaptures) {
30 1
            throw new TransitionPatternMismatch($transition, self::$pattern);
31
        }
32
33 15
        return new self(
34 15
            FlyweightState::named($matches['current_state']),
35 15
            FlyweightInput::named($matches['input']),
36 15
            FlyweightState::named($matches['next_state'])
37
        );
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 17
    public static function getPattern() : string
44
    {
45 17
        return self::$pattern;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     *
51
     * @throws InvalidPattern
52
     */
53 2
    public static function usePattern(string $pattern)
54
    {
55 2
        if (@preg_match($pattern, null) === false) {
56 1
            throw new InvalidPattern($pattern);
57
        }
58
59 1
        self::$pattern = $pattern;
60 1
    }
61
}
62