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 — master ( 14e86b...9d5c74 )
by Gilles
02:13
created

Matcher   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parser() 0 9 2
A match() 0 14 4
1
<?php
2
3
namespace PHPFunctional\PatternMatching;
4
5
class Matcher
6
{
7
    protected static function parser() {
8
        static $parser = null;
9
10
        if(is_null($parser)) {
11
            $parser = new Parser();
12
        }
13
14
        return $parser;
15
    }
16
17
    /**
18
     * @param mixed $value
19 4
     * @param array $patterns
20
     * @return mixed
21
     */
22
    public static function match($value, array $patterns)
23
    {
24 4
        foreach($patterns as $pattern => $callback) {
25 4
            $match = static::parser()->parse($value, $pattern);
26
27
            if($match !== false) {
28
                return is_callable($callback) ?
29
                    call_user_func_array($callback, $match) :
30 4
                    $callback;
31
            }
32
        }
33
34
        throw new \RuntimeException('Non-exhaustive patterns.');
35
    }
36
}