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.

XmlMatcher::match()   B
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 8.7624
cc 5
eloc 12
nc 4
nop 2
1
<?php
2
3
namespace Coduo\PHPMatcher\Matcher;
4
5
use Coduo\PHPMatcher\Matcher\Pattern\Assert\Xml;
6
use LSS\XML2Array;
7
8
final class XmlMatcher extends Matcher
9
{
10
    /**
11
     * @var
12
     */
13
    private $matcher;
14
15
    /**
16
     * @param ValueMatcher $matcher
17
     */
18
    public function __construct(ValueMatcher $matcher)
19
    {
20
        $this->matcher = $matcher;
21
    }
22
23
    /**
24
     * {@inheritDoc}
25
     */
26
    public function match($value, $pattern)
27
    {
28
        if (parent::match($value, $pattern)) {
29
            return true;
30
        }
31
32
        if (!Xml::isValid($value) || !Xml::isValid($pattern)) {
33
            return false;
34
        }
35
36
        $arrayValue = XML2Array::createArray($value);
37
        $arrayPattern = XML2Array::createArray($pattern);
38
39
        $match = $this->matcher->match($arrayValue, $arrayPattern);
40
        if (!$match) {
41
            $this->error = $this->matcher->getError();
42
            return false;
43
        }
44
45
        return true;
46
    }
47
48
    /**
49
     * {@inheritDoc}
50
     */
51
    public function canMatch($pattern)
52
    {
53
        return Xml::isValid($pattern);
54
    }
55
}
56