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.

StringMatcher::match()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 15
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 15
loc 15
rs 9.4285
cc 3
eloc 9
nc 3
nop 2
1
<?php
2
3
namespace Coduo\PHPMatcher\Matcher;
4
5
use Coduo\PHPMatcher\Parser;
6
use Coduo\ToString\StringConverter;
7
8 View Code Duplication
final class StringMatcher extends Matcher
0 ignored issues
show
Duplication introduced by
This class 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...
9
{
10
    /**
11
     * @var Parser
12
     */
13
    private $parser;
14
15
    /**
16
     * @param Parser $parser
17
     */
18
    public function __construct(Parser $parser)
19
    {
20
        $this->parser = $parser;
21
    }
22
23
    /**
24
     * {@inheritDoc}
25
     */
26
    public function match($value, $pattern)
27
    {
28
        if (!is_string($value)) {
29
            $this->error = sprintf("%s \"%s\" is not a valid string.", gettype($value), new StringConverter($value));
30
            return false;
31
        }
32
33
        $typePattern = $this->parser->parse($pattern);
34
        if (!$typePattern->matchExpanders($value)) {
35
            $this->error = $typePattern->getError();
36
            return false;
37
        }
38
39
        return true;
40
    }
41
42
    /**
43
     * {@inheritDoc}
44
     */
45
    public function canMatch($pattern)
46
    {
47
        if (!is_string($pattern)) {
48
            return false;
49
        }
50
51
        return $this->parser->hasValidSyntax($pattern) && $this->parser->parse($pattern)->is('string');
52
    }
53
}
54