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
09:19
created

ClassMatcher   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 16.07 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 39.13%

Importance

Changes 0
Metric Value
dl 9
loc 56
ccs 9
cts 23
cp 0.3913
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A withClass() 0 3 1
A __construct() 0 4 1
A describeTo() 8 8 2
A matchesSafelyWithDiagnosticDescription() 0 15 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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