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.

DirectChildElementMatcher::describeTo()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 6
ccs 6
cts 6
cp 1
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 DirectChildElementMatcher extends TypeSafeDiagnosingMatcher {
10
11
	/**
12
	 * @var Matcher
13
	 */
14
	private $matcher;
15
16
	public static function havingDirectChild( Matcher $elementMatcher = null ) {
17
		return new static( $elementMatcher );
18
	}
19
20
	public function __construct( Matcher $matcher = null ) {
21
		parent::__construct( \DOMNode::class );
22
		$this->matcher = $matcher;
23
	}
24
25 4
	public function describeTo( Description $description ) {
26 4
		$description->appendText( 'having direct child ' );
27 4
		if ( $this->matcher ) {
28 4
			$description->appendDescriptionOf( $this->matcher );
29 4
		}
30 4
	}
31
32
	/**
33
	 * @param \DOMDocument|\DOMNode $item
34
	 * @param Description $mismatchDescription
35
	 *
36
	 * @return bool
37
	 */
38 6
	protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) {
39 6
		if ( $item instanceof \DOMDocument ) {
40 6
			$item = $item->documentElement->childNodes->item( 0 );
41 6
		}
42 6
		$directChildren = $item->childNodes;
43
44 6
		if ( $directChildren->length === 0 ) {
45 1
			$mismatchDescription->appendText( 'with no direct children' );
46 1
			return false;
47
		}
48
49 6
		$childWord = $directChildren->length === 1 ? 'child' : 'children';
50
51 6
		$mismatchDescription->appendText( "with direct {$childWord} " );
52
53 6
		if ( !$this->matcher ) {
54 1
			return $directChildren->length !== 0;
55
		}
56
57 5
		foreach ( $directChildren as $child ) {
58 5
			if ( $this->matcher->matches( $child ) ) {
59 1
				return true;
60
			}
61 4
		}
62
63 4
		$this->matcher->describeMismatch( $child, $mismatchDescription );
64
65 4
		return false;
66
	}
67
68
}
69