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.

OrMatcher   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 60
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A match() 0 11 3
A matchChild() 0 12 3
A canMatch() 0 4 2
1
<?php
2
3
namespace Coduo\PHPMatcher\Matcher;
4
5
final class OrMatcher extends Matcher
6
{
7
    const MATCH_PATTERN = "/\|\|/";
8
9
    /**
10
     * @var ChainMatcher
11
     */
12
    private $chainMatcher;
13
14
    /**
15
     * @param ChainMatcher $chainMatcher
16
     */
17
    public function __construct(ChainMatcher $chainMatcher)
18
    {
19
        $this->chainMatcher = $chainMatcher;
20
    }
21
22
    /**
23
     * {@inheritDoc}
24
     */
25
    public function match($value, $pattern)
26
    {
27
        $patterns = explode('||', $pattern);
28
        foreach ($patterns as $childPattern) {
29
            if ($this->matchChild($value, $childPattern)){
30
                return true;
31
            }
32
        }
33
34
        return false;
35
    }
36
37
    /**
38
     * Matches single pattern
39
     *
40
     * @param $value
41
     * @param $pattern
42
     * @return bool
43
     */
44
    private function matchChild($value, $pattern)
45
    {
46
        if (!$this->chainMatcher->canMatch($pattern)) {
47
            return false;
48
        }
49
50
        if ($this->chainMatcher->match($value, $pattern)) {
51
            return true;
52
        }
53
54
        return false;
55
    }
56
57
    /**
58
     * {@inheritDoc}
59
     */
60
    public function canMatch($pattern)
61
    {
62
        return is_string($pattern) && 0 !== preg_match_all(self::MATCH_PATTERN, $pattern, $matches);
63
    }
64
}
65