ClassMatcher   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 64.71%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 45
ccs 11
cts 17
cp 0.6471
rs 10
c 0
b 0
f 0

4 Methods

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