TagNameMatcher   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 62.5%

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 10
cts 16
cp 0.625
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A withTagName() 0 3 1
A __construct() 0 4 1
A describeTo() 0 4 1
A matchesSafelyWithDiagnosticDescription() 0 9 2
1
<?php
2
3
namespace WMDE\HamcrestHtml;
4
5
use Hamcrest\Description;
6
use Hamcrest\Matcher;
7
use Hamcrest\Util;
8
9
class TagNameMatcher extends TagMatcher {
10
11
	/**
12
	 * @var Matcher
13
	 */
14
	private $tagNameMatcher;
15
16
	/**
17
	 * @param Matcher|string $tagName
18
	 *
19
	 * @return self
20
	 */
21
	public static function withTagName( $tagName ) {
22
		return new static( Util::wrapValueWithIsEqual( $tagName ) );
23
	}
24
25
	public function __construct( Matcher $tagNameMatcher ) {
26
		parent::__construct();
27
		$this->tagNameMatcher = $tagNameMatcher;
28
	}
29
30 5
	public function describeTo( Description $description ) {
31 5
		$description->appendText( 'with tag name ' )
32 5
			->appendDescriptionOf( $this->tagNameMatcher );
33 5
	}
34
35
	/**
36
	 * @param \DOMElement $item
37
	 * @param Description $mismatchDescription
38
	 *
39
	 * @return bool
40
	 */
41 11
	protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) {
42 11
		if ( $this->tagNameMatcher->matches( $item->tagName ) ) {
43 6
			return true;
44
		}
45
46 8
		$mismatchDescription->appendText( 'tag name ' );
47 8
		$this->tagNameMatcher->describeMismatch( $item->tagName, $mismatchDescription );
48 8
		return false;
49
	}
50
51
}
52