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.

OneOf   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 23.4 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 8
c 1
b 1
f 0
lcom 1
cbo 2
dl 11
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 4
A match() 11 11 3
A getError() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Coduo\PHPMatcher\Matcher\Pattern\Expander;
4
5
use Coduo\PHPMatcher\Matcher\Pattern\PatternExpander;
6
use Coduo\ToString\StringConverter;
7
8
final class OneOf implements PatternExpander
9
{
10
    /**
11
     * @var PatternExpander[]
12
     */
13
    protected $expanders;
14
15
    protected $error;
16
17
    public function __construct()
18
    {
19
        if (func_num_args() < 2) {
20
            throw new \InvalidArgumentException("OneOf expander require at least two expanders.");
21
        }
22
        foreach (func_get_args() as $argument) {
23
            if (!$argument instanceof PatternExpander) {
24
                throw new \InvalidArgumentException("OneOf expander require each argument to be a valid PatternExpander.");
25
            }
26
27
            $this->expanders[] = $argument;
28
        }
29
    }
30
31
    /**
32
     * @param $value
33
     * @return boolean
34
     */
35 View Code Duplication
    public function match($value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        foreach ($this->expanders as $expander) {
38
            if ($expander->match($value)) {
39
                return true;
40
            }
41
        }
42
43
        $this->error = sprintf("Any expander available in OneOf expander does not match \"%s\".", new StringConverter($value));
44
        return false;
45
    }
46
47
    /**
48
     * @return string|null
49
     */
50
    public function getError()
51
    {
52
        return $this->error;
53
    }
54
}
55