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   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 52
ccs 16
cts 16
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A new() 0 15 3
A getPattern() 0 4 1
A usePattern() 0 8 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