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.
Passed
Pull Request — master (#9)
by no
02:41
created

ChildElementMatcher::havingChild()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WMDE\HamcrestHtml;
4
5
use Hamcrest\Description;
6
use Hamcrest\Matcher;
7
use Hamcrest\TypeSafeDiagnosingMatcher;
8
9
class ChildElementMatcher extends TypeSafeDiagnosingMatcher
10
{
11
12
    /**
13
     * @var Matcher|string|null
14
     */
15
    private $matcher;
16
17
    /**
18
     * @param Matcher|string|null $elementMatcher
19
     *
20
     * @return self
21
     */
22
    public static function havingChild($elementMatcher = null) {
23
        return new static($elementMatcher);
24
    }
25
26
    /**
27
     * @param Matcher|string|null $matcher
28
     */
29
    public function __construct($matcher = null)
30
    {
31
        parent::__construct(\DOMNode::class);
32
        $this->matcher = $matcher;
33
    }
34
35 7 View Code Duplication
    public function describeTo(Description $description)
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 7
        $description->appendText('having child ');
38 7
        if ($this->matcher) {
39 6
            if ($this->matcher instanceof Matcher) {
40 6
                $description->appendDescriptionOf( $this->matcher );
41 6
            } else {
42
                $description->appendValue($this->matcher);
43
            }
44 6
        }
45 7
    }
46
47
    /**
48
     * @param \DOMDocument|\DOMNode $item
49
     * @param Description $mismatchDescription
50
     *
51
     * @return bool
52
     */
53 17
    protected function matchesSafelyWithDiagnosticDescription($item, Description $mismatchDescription)
54
    {
55 17
        if ($item instanceof \DOMDocument) {
56 16
            $item = $item->documentElement->childNodes->item(0);
57
            /** @var \DOMElement $item */
58 16
        }
59 17
        $directChildren = $item->childNodes;
60
61 17
        if ($directChildren->length === 0) {
62 1
            $mismatchDescription->appendText('having no children');
63 1
            return false;
64
        }
65
66 16
        if (!$this->matcher) {
67
            return true;
68
        }
69
70 16
        if ($this->matcher instanceof Matcher) {
71
//throw new \Exception('Still a Matcher');
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
72 16
            foreach (new XmlNodeRecursiveIterator($directChildren) as $child) {
73 16
                if ($this->matcher->matches($child)) {
74 10
                    return true;
75
                }
76 11
            }
77 6
        } else {
78
            if ($item->getElementsByTagName($this->matcher)->length !== 0) {
79
                return true;
80
            }
81
        }
82
83 6
        $mismatchDescription->appendText('having no children ')->appendDescriptionOf($this->matcher);
0 ignored issues
show
Bug introduced by
It seems like $this->matcher can also be of type string; however, Hamcrest\Description::appendDescriptionOf() does only seem to accept object<Hamcrest\SelfDescribing>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
84 6
        return false;
85
    }
86
87
}
88