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.
Completed
Pull Request — master (#12)
by no
04:52
created
src/RootElementMatcher.php 2 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -8,60 +8,60 @@
 block discarded – undo
8 8
 
9 9
 class RootElementMatcher extends TypeSafeDiagnosingMatcher {
10 10
 
11
-	/**
12
-	 * @var Matcher
13
-	 */
14
-	private $tagMatcher;
11
+    /**
12
+     * @var Matcher
13
+     */
14
+    private $tagMatcher;
15 15
 
16
-	/**
17
-	 * @param Matcher|null $tagMatcher
18
-	 *
19
-	 * @return static
20
-	 */
21
-	public static function havingRootElement( Matcher $tagMatcher = null ) {
22
-		return new static( $tagMatcher );
23
-	}
16
+    /**
17
+     * @param Matcher|null $tagMatcher
18
+     *
19
+     * @return static
20
+     */
21
+    public static function havingRootElement( Matcher $tagMatcher = null ) {
22
+        return new static( $tagMatcher );
23
+    }
24 24
 
25
-	public function __construct( Matcher $tagMatcher = null ) {
26
-		parent::__construct( self::TYPE_OBJECT, \DOMDocument::class );
27
-		$this->tagMatcher = $tagMatcher;
28
-	}
25
+    public function __construct( Matcher $tagMatcher = null ) {
26
+        parent::__construct( self::TYPE_OBJECT, \DOMDocument::class );
27
+        $this->tagMatcher = $tagMatcher;
28
+    }
29 29
 
30
-	public function describeTo( Description $description ) {
31
-		$description->appendText( 'having root element ' );
32
-		if ( $this->tagMatcher ) {
33
-			$description->appendDescriptionOf( $this->tagMatcher );
34
-		}
35
-	}
30
+    public function describeTo( Description $description ) {
31
+        $description->appendText( 'having root element ' );
32
+        if ( $this->tagMatcher ) {
33
+            $description->appendDescriptionOf( $this->tagMatcher );
34
+        }
35
+    }
36 36
 
37
-	/**
38
-	 * @param \DOMDocument $item
39
-	 * @param Description $mismatchDescription
40
-	 *
41
-	 * @return bool
42
-	 */
43
-	protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) {
44
-		$DOMNodeList = $item->documentElement->childNodes->item( 0 )->childNodes;
45
-		if ( $DOMNodeList->length > 1 ) {
46
-			// TODO Test this description
47
-			$mismatchDescription->appendText( 'having ' . $DOMNodeList->length . ' root elements ' );
48
-			return false;
49
-		}
37
+    /**
38
+     * @param \DOMDocument $item
39
+     * @param Description $mismatchDescription
40
+     *
41
+     * @return bool
42
+     */
43
+    protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) {
44
+        $DOMNodeList = $item->documentElement->childNodes->item( 0 )->childNodes;
45
+        if ( $DOMNodeList->length > 1 ) {
46
+            // TODO Test this description
47
+            $mismatchDescription->appendText( 'having ' . $DOMNodeList->length . ' root elements ' );
48
+            return false;
49
+        }
50 50
 
51
-		$target = $DOMNodeList->item( 0 );
52
-		if ( !$target ) {
53
-			// TODO Reproduce?
54
-			$mismatchDescription->appendText( 'having no root elements ' );
55
-			return false;
56
-		}
51
+        $target = $DOMNodeList->item( 0 );
52
+        if ( !$target ) {
53
+            // TODO Reproduce?
54
+            $mismatchDescription->appendText( 'having no root elements ' );
55
+            return false;
56
+        }
57 57
 
58
-		if ( $this->tagMatcher ) {
59
-			$mismatchDescription->appendText( 'root element ' );
60
-			$this->tagMatcher->describeMismatch( $target, $mismatchDescription );
61
-			return $this->tagMatcher->matches( $target );
62
-		}
58
+        if ( $this->tagMatcher ) {
59
+            $mismatchDescription->appendText( 'root element ' );
60
+            $this->tagMatcher->describeMismatch( $target, $mismatchDescription );
61
+            return $this->tagMatcher->matches( $target );
62
+        }
63 63
 
64
-		return true;
65
-	}
64
+        return true;
65
+    }
66 66
 
67 67
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -18,19 +18,19 @@  discard block
 block discarded – undo
18 18
 	 *
19 19
 	 * @return static
20 20
 	 */
21
-	public static function havingRootElement( Matcher $tagMatcher = null ) {
22
-		return new static( $tagMatcher );
21
+	public static function havingRootElement(Matcher $tagMatcher = null) {
22
+		return new static($tagMatcher);
23 23
 	}
24 24
 
25
-	public function __construct( Matcher $tagMatcher = null ) {
26
-		parent::__construct( self::TYPE_OBJECT, \DOMDocument::class );
25
+	public function __construct(Matcher $tagMatcher = null) {
26
+		parent::__construct(self::TYPE_OBJECT, \DOMDocument::class);
27 27
 		$this->tagMatcher = $tagMatcher;
28 28
 	}
29 29
 
30
-	public function describeTo( Description $description ) {
31
-		$description->appendText( 'having root element ' );
32
-		if ( $this->tagMatcher ) {
33
-			$description->appendDescriptionOf( $this->tagMatcher );
30
+	public function describeTo(Description $description) {
31
+		$description->appendText('having root element ');
32
+		if ($this->tagMatcher) {
33
+			$description->appendDescriptionOf($this->tagMatcher);
34 34
 		}
35 35
 	}
36 36
 
@@ -40,25 +40,25 @@  discard block
 block discarded – undo
40 40
 	 *
41 41
 	 * @return bool
42 42
 	 */
43
-	protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) {
44
-		$DOMNodeList = $item->documentElement->childNodes->item( 0 )->childNodes;
45
-		if ( $DOMNodeList->length > 1 ) {
43
+	protected function matchesSafelyWithDiagnosticDescription($item, Description $mismatchDescription) {
44
+		$DOMNodeList = $item->documentElement->childNodes->item(0)->childNodes;
45
+		if ($DOMNodeList->length > 1) {
46 46
 			// TODO Test this description
47
-			$mismatchDescription->appendText( 'having ' . $DOMNodeList->length . ' root elements ' );
47
+			$mismatchDescription->appendText('having ' . $DOMNodeList->length . ' root elements ');
48 48
 			return false;
49 49
 		}
50 50
 
51
-		$target = $DOMNodeList->item( 0 );
52
-		if ( !$target ) {
51
+		$target = $DOMNodeList->item(0);
52
+		if (!$target) {
53 53
 			// TODO Reproduce?
54
-			$mismatchDescription->appendText( 'having no root elements ' );
54
+			$mismatchDescription->appendText('having no root elements ');
55 55
 			return false;
56 56
 		}
57 57
 
58
-		if ( $this->tagMatcher ) {
59
-			$mismatchDescription->appendText( 'root element ' );
60
-			$this->tagMatcher->describeMismatch( $target, $mismatchDescription );
61
-			return $this->tagMatcher->matches( $target );
58
+		if ($this->tagMatcher) {
59
+			$mismatchDescription->appendText('root element ');
60
+			$this->tagMatcher->describeMismatch($target, $mismatchDescription);
61
+			return $this->tagMatcher->matches($target);
62 62
 		}
63 63
 
64 64
 		return true;
Please login to merge, or discard this patch.
src/DirectChildElementMatcher.php 2 patches
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -8,61 +8,61 @@
 block discarded – undo
8 8
 
9 9
 class DirectChildElementMatcher extends TypeSafeDiagnosingMatcher {
10 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
-	public function describeTo( Description $description ) {
26
-		$description->appendText( 'having direct child ' );
27
-		if ( $this->matcher ) {
28
-			$description->appendDescriptionOf( $this->matcher );
29
-		}
30
-	}
31
-
32
-	/**
33
-	 * @param \DOMDocument|\DOMNode $item
34
-	 * @param Description $mismatchDescription
35
-	 *
36
-	 * @return bool
37
-	 */
38
-	protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) {
39
-		if ( $item instanceof \DOMDocument ) {
40
-			$item = $item->documentElement->childNodes->item( 0 );
41
-		}
42
-		$directChildren = $item->childNodes;
43
-
44
-		if ( $directChildren->length === 0 ) {
45
-			$mismatchDescription->appendText( 'with no direct children' );
46
-			return false;
47
-		}
48
-
49
-		$childWord = $directChildren->length === 1 ? 'child' : 'children';
50
-
51
-		$mismatchDescription->appendText( "with direct {$childWord} " );
52
-
53
-		if ( !$this->matcher ) {
54
-			return $directChildren->length !== 0;
55
-		}
56
-
57
-		foreach ( $directChildren as $child ) {
58
-			if ( $this->matcher->matches( $child ) ) {
59
-				return true;
60
-			}
61
-		}
62
-
63
-		$this->matcher->describeMismatch( $child, $mismatchDescription );
64
-
65
-		return false;
66
-	}
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
+    public function describeTo( Description $description ) {
26
+        $description->appendText( 'having direct child ' );
27
+        if ( $this->matcher ) {
28
+            $description->appendDescriptionOf( $this->matcher );
29
+        }
30
+    }
31
+
32
+    /**
33
+     * @param \DOMDocument|\DOMNode $item
34
+     * @param Description $mismatchDescription
35
+     *
36
+     * @return bool
37
+     */
38
+    protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) {
39
+        if ( $item instanceof \DOMDocument ) {
40
+            $item = $item->documentElement->childNodes->item( 0 );
41
+        }
42
+        $directChildren = $item->childNodes;
43
+
44
+        if ( $directChildren->length === 0 ) {
45
+            $mismatchDescription->appendText( 'with no direct children' );
46
+            return false;
47
+        }
48
+
49
+        $childWord = $directChildren->length === 1 ? 'child' : 'children';
50
+
51
+        $mismatchDescription->appendText( "with direct {$childWord} " );
52
+
53
+        if ( !$this->matcher ) {
54
+            return $directChildren->length !== 0;
55
+        }
56
+
57
+        foreach ( $directChildren as $child ) {
58
+            if ( $this->matcher->matches( $child ) ) {
59
+                return true;
60
+            }
61
+        }
62
+
63
+        $this->matcher->describeMismatch( $child, $mismatchDescription );
64
+
65
+        return false;
66
+    }
67 67
 
68 68
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -13,19 +13,19 @@  discard block
 block discarded – undo
13 13
 	 */
14 14
 	private $matcher;
15 15
 
16
-	public static function havingDirectChild( Matcher $elementMatcher = null ) {
17
-		return new static( $elementMatcher );
16
+	public static function havingDirectChild(Matcher $elementMatcher = null) {
17
+		return new static($elementMatcher);
18 18
 	}
19 19
 
20
-	public function __construct( Matcher $matcher = null ) {
21
-		parent::__construct( \DOMNode::class );
20
+	public function __construct(Matcher $matcher = null) {
21
+		parent::__construct(\DOMNode::class);
22 22
 		$this->matcher = $matcher;
23 23
 	}
24 24
 
25
-	public function describeTo( Description $description ) {
26
-		$description->appendText( 'having direct child ' );
27
-		if ( $this->matcher ) {
28
-			$description->appendDescriptionOf( $this->matcher );
25
+	public function describeTo(Description $description) {
26
+		$description->appendText('having direct child ');
27
+		if ($this->matcher) {
28
+			$description->appendDescriptionOf($this->matcher);
29 29
 		}
30 30
 	}
31 31
 
@@ -35,32 +35,32 @@  discard block
 block discarded – undo
35 35
 	 *
36 36
 	 * @return bool
37 37
 	 */
38
-	protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) {
39
-		if ( $item instanceof \DOMDocument ) {
40
-			$item = $item->documentElement->childNodes->item( 0 );
38
+	protected function matchesSafelyWithDiagnosticDescription($item, Description $mismatchDescription) {
39
+		if ($item instanceof \DOMDocument) {
40
+			$item = $item->documentElement->childNodes->item(0);
41 41
 		}
42 42
 		$directChildren = $item->childNodes;
43 43
 
44
-		if ( $directChildren->length === 0 ) {
45
-			$mismatchDescription->appendText( 'with no direct children' );
44
+		if ($directChildren->length === 0) {
45
+			$mismatchDescription->appendText('with no direct children');
46 46
 			return false;
47 47
 		}
48 48
 
49 49
 		$childWord = $directChildren->length === 1 ? 'child' : 'children';
50 50
 
51
-		$mismatchDescription->appendText( "with direct {$childWord} " );
51
+		$mismatchDescription->appendText("with direct {$childWord} ");
52 52
 
53
-		if ( !$this->matcher ) {
53
+		if (!$this->matcher) {
54 54
 			return $directChildren->length !== 0;
55 55
 		}
56 56
 
57
-		foreach ( $directChildren as $child ) {
58
-			if ( $this->matcher->matches( $child ) ) {
57
+		foreach ($directChildren as $child) {
58
+			if ($this->matcher->matches($child)) {
59 59
 				return true;
60 60
 			}
61 61
 		}
62 62
 
63
-		$this->matcher->describeMismatch( $child, $mismatchDescription );
63
+		$this->matcher->describeMismatch($child, $mismatchDescription);
64 64
 
65 65
 		return false;
66 66
 	}
Please login to merge, or discard this patch.
src/ChildElementMatcher.php 2 patches
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -8,57 +8,57 @@
 block discarded – undo
8 8
 
9 9
 class ChildElementMatcher extends TypeSafeDiagnosingMatcher {
10 10
 
11
-	/**
12
-	 * @var Matcher|null
13
-	 */
14
-	private $matcher;
11
+    /**
12
+     * @var Matcher|null
13
+     */
14
+    private $matcher;
15 15
 
16
-	public static function havingChild( Matcher $elementMatcher = null ) {
17
-		return new static( $elementMatcher );
18
-	}
16
+    public static function havingChild( Matcher $elementMatcher = null ) {
17
+        return new static( $elementMatcher );
18
+    }
19 19
 
20
-	public function __construct( Matcher $matcher = null ) {
21
-		parent::__construct( \DOMNode::class );
22
-		$this->matcher = $matcher;
23
-	}
20
+    public function __construct( Matcher $matcher = null ) {
21
+        parent::__construct( \DOMNode::class );
22
+        $this->matcher = $matcher;
23
+    }
24 24
 
25
-	public function describeTo( Description $description ) {
26
-		$description->appendText( 'having child ' );
27
-		if ( $this->matcher ) {
28
-			$description->appendDescriptionOf( $this->matcher );
29
-		}
30
-	}
25
+    public function describeTo( Description $description ) {
26
+        $description->appendText( 'having child ' );
27
+        if ( $this->matcher ) {
28
+            $description->appendDescriptionOf( $this->matcher );
29
+        }
30
+    }
31 31
 
32
-	/**
33
-	 * @param \DOMDocument|\DOMNode $item
34
-	 * @param Description $mismatchDescription
35
-	 *
36
-	 * @return bool
37
-	 */
38
-	protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) {
39
-		if ( $item instanceof \DOMDocument ) {
40
-			$directChildren = $item->documentElement->childNodes->item( 0 )->childNodes;
41
-		} else {
42
-			$directChildren = $item->childNodes;
43
-		}
32
+    /**
33
+     * @param \DOMDocument|\DOMNode $item
34
+     * @param Description $mismatchDescription
35
+     *
36
+     * @return bool
37
+     */
38
+    protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) {
39
+        if ( $item instanceof \DOMDocument ) {
40
+            $directChildren = $item->documentElement->childNodes->item( 0 )->childNodes;
41
+        } else {
42
+            $directChildren = $item->childNodes;
43
+        }
44 44
 
45
-		if ( $directChildren->length === 0 ) {
46
-			$mismatchDescription->appendText( 'having no children' );
47
-			return false;
48
-		}
45
+        if ( $directChildren->length === 0 ) {
46
+            $mismatchDescription->appendText( 'having no children' );
47
+            return false;
48
+        }
49 49
 
50
-		if ( !$this->matcher ) {
51
-			return $directChildren->length > 0;
52
-		}
50
+        if ( !$this->matcher ) {
51
+            return $directChildren->length > 0;
52
+        }
53 53
 
54
-		foreach ( new XmlNodeRecursiveIterator( $directChildren ) as $child ) {
55
-			if ( $this->matcher->matches( $child ) ) {
56
-				return true;
57
-			}
58
-		}
54
+        foreach ( new XmlNodeRecursiveIterator( $directChildren ) as $child ) {
55
+            if ( $this->matcher->matches( $child ) ) {
56
+                return true;
57
+            }
58
+        }
59 59
 
60
-		$mismatchDescription->appendText( 'having no children ' )->appendDescriptionOf( $this->matcher );
61
-		return false;
62
-	}
60
+        $mismatchDescription->appendText( 'having no children ' )->appendDescriptionOf( $this->matcher );
61
+        return false;
62
+    }
63 63
 
64 64
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -13,19 +13,19 @@  discard block
 block discarded – undo
13 13
 	 */
14 14
 	private $matcher;
15 15
 
16
-	public static function havingChild( Matcher $elementMatcher = null ) {
17
-		return new static( $elementMatcher );
16
+	public static function havingChild(Matcher $elementMatcher = null) {
17
+		return new static($elementMatcher);
18 18
 	}
19 19
 
20
-	public function __construct( Matcher $matcher = null ) {
21
-		parent::__construct( \DOMNode::class );
20
+	public function __construct(Matcher $matcher = null) {
21
+		parent::__construct(\DOMNode::class);
22 22
 		$this->matcher = $matcher;
23 23
 	}
24 24
 
25
-	public function describeTo( Description $description ) {
26
-		$description->appendText( 'having child ' );
27
-		if ( $this->matcher ) {
28
-			$description->appendDescriptionOf( $this->matcher );
25
+	public function describeTo(Description $description) {
26
+		$description->appendText('having child ');
27
+		if ($this->matcher) {
28
+			$description->appendDescriptionOf($this->matcher);
29 29
 		}
30 30
 	}
31 31
 
@@ -35,29 +35,29 @@  discard block
 block discarded – undo
35 35
 	 *
36 36
 	 * @return bool
37 37
 	 */
38
-	protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) {
39
-		if ( $item instanceof \DOMDocument ) {
40
-			$directChildren = $item->documentElement->childNodes->item( 0 )->childNodes;
38
+	protected function matchesSafelyWithDiagnosticDescription($item, Description $mismatchDescription) {
39
+		if ($item instanceof \DOMDocument) {
40
+			$directChildren = $item->documentElement->childNodes->item(0)->childNodes;
41 41
 		} else {
42 42
 			$directChildren = $item->childNodes;
43 43
 		}
44 44
 
45
-		if ( $directChildren->length === 0 ) {
46
-			$mismatchDescription->appendText( 'having no children' );
45
+		if ($directChildren->length === 0) {
46
+			$mismatchDescription->appendText('having no children');
47 47
 			return false;
48 48
 		}
49 49
 
50
-		if ( !$this->matcher ) {
50
+		if (!$this->matcher) {
51 51
 			return $directChildren->length > 0;
52 52
 		}
53 53
 
54
-		foreach ( new XmlNodeRecursiveIterator( $directChildren ) as $child ) {
55
-			if ( $this->matcher->matches( $child ) ) {
54
+		foreach (new XmlNodeRecursiveIterator($directChildren) as $child) {
55
+			if ($this->matcher->matches($child)) {
56 56
 				return true;
57 57
 			}
58 58
 		}
59 59
 
60
-		$mismatchDescription->appendText( 'having no children ' )->appendDescriptionOf( $this->matcher );
60
+		$mismatchDescription->appendText('having no children ')->appendDescriptionOf($this->matcher);
61 61
 		return false;
62 62
 	}
63 63
 
Please login to merge, or discard this patch.
src/TagNameMatcher.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -8,44 +8,44 @@
 block discarded – undo
8 8
 
9 9
 class TagNameMatcher extends TagMatcher {
10 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
-	public function describeTo( Description $description ) {
31
-		$description->appendText( 'with tag name ' )
32
-			->appendDescriptionOf( $this->tagNameMatcher );
33
-	}
34
-
35
-	/**
36
-	 * @param \DOMElement $item
37
-	 * @param Description $mismatchDescription
38
-	 *
39
-	 * @return bool
40
-	 */
41
-	protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) {
42
-		if ( $this->tagNameMatcher->matches( $item->tagName ) ) {
43
-			return true;
44
-		}
45
-
46
-		$mismatchDescription->appendText( 'tag name ' );
47
-		$this->tagNameMatcher->describeMismatch( $item->tagName, $mismatchDescription );
48
-		return false;
49
-	}
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
+    public function describeTo( Description $description ) {
31
+        $description->appendText( 'with tag name ' )
32
+            ->appendDescriptionOf( $this->tagNameMatcher );
33
+    }
34
+
35
+    /**
36
+     * @param \DOMElement $item
37
+     * @param Description $mismatchDescription
38
+     *
39
+     * @return bool
40
+     */
41
+    protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) {
42
+        if ( $this->tagNameMatcher->matches( $item->tagName ) ) {
43
+            return true;
44
+        }
45
+
46
+        $mismatchDescription->appendText( 'tag name ' );
47
+        $this->tagNameMatcher->describeMismatch( $item->tagName, $mismatchDescription );
48
+        return false;
49
+    }
50 50
 
51 51
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -18,18 +18,18 @@  discard block
 block discarded – undo
18 18
 	 *
19 19
 	 * @return self
20 20
 	 */
21
-	public static function withTagName( $tagName ) {
22
-		return new static( Util::wrapValueWithIsEqual( $tagName ) );
21
+	public static function withTagName($tagName) {
22
+		return new static(Util::wrapValueWithIsEqual($tagName));
23 23
 	}
24 24
 
25
-	public function __construct( Matcher $tagNameMatcher ) {
25
+	public function __construct(Matcher $tagNameMatcher) {
26 26
 		parent::__construct();
27 27
 		$this->tagNameMatcher = $tagNameMatcher;
28 28
 	}
29 29
 
30
-	public function describeTo( Description $description ) {
31
-		$description->appendText( 'with tag name ' )
32
-			->appendDescriptionOf( $this->tagNameMatcher );
30
+	public function describeTo(Description $description) {
31
+		$description->appendText('with tag name ')
32
+			->appendDescriptionOf($this->tagNameMatcher);
33 33
 	}
34 34
 
35 35
 	/**
@@ -38,13 +38,13 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @return bool
40 40
 	 */
41
-	protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) {
42
-		if ( $this->tagNameMatcher->matches( $item->tagName ) ) {
41
+	protected function matchesSafelyWithDiagnosticDescription($item, Description $mismatchDescription) {
42
+		if ($this->tagNameMatcher->matches($item->tagName)) {
43 43
 			return true;
44 44
 		}
45 45
 
46
-		$mismatchDescription->appendText( 'tag name ' );
47
-		$this->tagNameMatcher->describeMismatch( $item->tagName, $mismatchDescription );
46
+		$mismatchDescription->appendText('tag name ');
47
+		$this->tagNameMatcher->describeMismatch($item->tagName, $mismatchDescription);
48 48
 		return false;
49 49
 	}
50 50
 
Please login to merge, or discard this patch.
src/HtmlMatcher.php 2 patches
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -8,99 +8,99 @@
 block discarded – undo
8 8
 
9 9
 class HtmlMatcher extends DiagnosingMatcher {
10 10
 
11
-	/**
12
-	 * @link http://www.xmlsoft.org/html/libxml-xmlerror.html#xmlParserErrors
13
-	 * @link https://github.com/Chronic-Dev/libxml2/blob/683f296a905710ff285c28b8644ef3a3d8be9486/include/libxml/xmlerror.h#L257
14
-	 */
15
-	const XML_UNKNOWN_TAG_ERROR_CODE = 801;
16
-
17
-	/**
18
-	 * @var Matcher
19
-	 */
20
-	private $elementMatcher;
21
-
22
-	/**
23
-	 * @param Matcher $elementMatcher
24
-	 *
25
-	 * @return self
26
-	 */
27
-	public static function htmlPiece( Matcher $elementMatcher = null ) {
28
-		return new static( $elementMatcher );
29
-	}
30
-
31
-	private function __construct( Matcher $elementMatcher = null ) {
32
-		$this->elementMatcher = $elementMatcher;
33
-	}
34
-
35
-	public function describeTo( Description $description ) {
36
-		$description->appendText( 'valid html piece ' );
37
-		if ( $this->elementMatcher ) {
38
-			$description->appendDescriptionOf( $this->elementMatcher );
39
-		}
40
-	}
41
-
42
-	protected function matchesWithDiagnosticDescription( $html, Description $mismatchDescription ) {
43
-		$internalErrors = libxml_use_internal_errors( true );
44
-		$document = new \DOMDocument();
45
-
46
-		$html = $this->escapeScriptTagContents( $html );
47
-
48
-		if ( !@$document->loadHTML( mb_convert_encoding( $html, 'HTML-ENTITIES', 'UTF-8' ) ) ) {
49
-			$mismatchDescription->appendText( 'there was some parsing error' );
50
-			return false;
51
-		}
52
-
53
-		$errors = libxml_get_errors();
54
-		libxml_clear_errors();
55
-		libxml_use_internal_errors( $internalErrors );
56
-
57
-		$result = true;
58
-		/** @var \LibXMLError $error */
59
-		foreach ( $errors as $error ) {
60
-			if ( $this->isUnknownTagError( $error ) ) {
61
-				continue;
62
-			}
63
-
64
-			$mismatchDescription->appendText( 'there was parsing error: ' )
65
-				->appendText( trim( $error->message ) )
66
-				->appendText( ' on line ' )
67
-				->appendText( $error->line );
68
-			$result = false;
69
-		}
70
-
71
-		if ( !$result ) {
72
-			return false;
73
-		}
74
-		$mismatchDescription->appendText( 'valid html piece ' );
75
-
76
-		if ( $this->elementMatcher ) {
77
-			$result = $this->elementMatcher->matches( $document );
78
-			$this->elementMatcher->describeMismatch( $document, $mismatchDescription );
79
-		}
80
-
81
-		$mismatchDescription->appendText( "\nActual html:\n" )->appendText( $html );
82
-
83
-		return $result;
84
-	}
85
-
86
-	/**
87
-	 * @param \LibXMLError $error
88
-	 *
89
-	 * @return bool
90
-	 */
91
-	private function isUnknownTagError( \LibXMLError $error ) {
92
-		return $error->code === self::XML_UNKNOWN_TAG_ERROR_CODE;
93
-	}
94
-
95
-	/**
96
-	 * @param string $html
97
-	 *
98
-	 * @return string HTML
99
-	 */
100
-	private function escapeScriptTagContents( $html ) {
101
-		return preg_replace_callback( '#(<script.*>)(.*)(</script>)#isU', function ( $matches ) {
102
-			return $matches[1] . str_replace( '</', '<\/', $matches[2] ) . $matches[3];
103
-		}, $html );
104
-	}
11
+    /**
12
+     * @link http://www.xmlsoft.org/html/libxml-xmlerror.html#xmlParserErrors
13
+     * @link https://github.com/Chronic-Dev/libxml2/blob/683f296a905710ff285c28b8644ef3a3d8be9486/include/libxml/xmlerror.h#L257
14
+     */
15
+    const XML_UNKNOWN_TAG_ERROR_CODE = 801;
16
+
17
+    /**
18
+     * @var Matcher
19
+     */
20
+    private $elementMatcher;
21
+
22
+    /**
23
+     * @param Matcher $elementMatcher
24
+     *
25
+     * @return self
26
+     */
27
+    public static function htmlPiece( Matcher $elementMatcher = null ) {
28
+        return new static( $elementMatcher );
29
+    }
30
+
31
+    private function __construct( Matcher $elementMatcher = null ) {
32
+        $this->elementMatcher = $elementMatcher;
33
+    }
34
+
35
+    public function describeTo( Description $description ) {
36
+        $description->appendText( 'valid html piece ' );
37
+        if ( $this->elementMatcher ) {
38
+            $description->appendDescriptionOf( $this->elementMatcher );
39
+        }
40
+    }
41
+
42
+    protected function matchesWithDiagnosticDescription( $html, Description $mismatchDescription ) {
43
+        $internalErrors = libxml_use_internal_errors( true );
44
+        $document = new \DOMDocument();
45
+
46
+        $html = $this->escapeScriptTagContents( $html );
47
+
48
+        if ( !@$document->loadHTML( mb_convert_encoding( $html, 'HTML-ENTITIES', 'UTF-8' ) ) ) {
49
+            $mismatchDescription->appendText( 'there was some parsing error' );
50
+            return false;
51
+        }
52
+
53
+        $errors = libxml_get_errors();
54
+        libxml_clear_errors();
55
+        libxml_use_internal_errors( $internalErrors );
56
+
57
+        $result = true;
58
+        /** @var \LibXMLError $error */
59
+        foreach ( $errors as $error ) {
60
+            if ( $this->isUnknownTagError( $error ) ) {
61
+                continue;
62
+            }
63
+
64
+            $mismatchDescription->appendText( 'there was parsing error: ' )
65
+                ->appendText( trim( $error->message ) )
66
+                ->appendText( ' on line ' )
67
+                ->appendText( $error->line );
68
+            $result = false;
69
+        }
70
+
71
+        if ( !$result ) {
72
+            return false;
73
+        }
74
+        $mismatchDescription->appendText( 'valid html piece ' );
75
+
76
+        if ( $this->elementMatcher ) {
77
+            $result = $this->elementMatcher->matches( $document );
78
+            $this->elementMatcher->describeMismatch( $document, $mismatchDescription );
79
+        }
80
+
81
+        $mismatchDescription->appendText( "\nActual html:\n" )->appendText( $html );
82
+
83
+        return $result;
84
+    }
85
+
86
+    /**
87
+     * @param \LibXMLError $error
88
+     *
89
+     * @return bool
90
+     */
91
+    private function isUnknownTagError( \LibXMLError $error ) {
92
+        return $error->code === self::XML_UNKNOWN_TAG_ERROR_CODE;
93
+    }
94
+
95
+    /**
96
+     * @param string $html
97
+     *
98
+     * @return string HTML
99
+     */
100
+    private function escapeScriptTagContents( $html ) {
101
+        return preg_replace_callback( '#(<script.*>)(.*)(</script>)#isU', function ( $matches ) {
102
+            return $matches[1] . str_replace( '</', '<\/', $matches[2] ) . $matches[3];
103
+        }, $html );
104
+    }
105 105
 
106 106
 }
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -24,61 +24,61 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @return self
26 26
 	 */
27
-	public static function htmlPiece( Matcher $elementMatcher = null ) {
28
-		return new static( $elementMatcher );
27
+	public static function htmlPiece(Matcher $elementMatcher = null) {
28
+		return new static($elementMatcher);
29 29
 	}
30 30
 
31
-	private function __construct( Matcher $elementMatcher = null ) {
31
+	private function __construct(Matcher $elementMatcher = null) {
32 32
 		$this->elementMatcher = $elementMatcher;
33 33
 	}
34 34
 
35
-	public function describeTo( Description $description ) {
36
-		$description->appendText( 'valid html piece ' );
37
-		if ( $this->elementMatcher ) {
38
-			$description->appendDescriptionOf( $this->elementMatcher );
35
+	public function describeTo(Description $description) {
36
+		$description->appendText('valid html piece ');
37
+		if ($this->elementMatcher) {
38
+			$description->appendDescriptionOf($this->elementMatcher);
39 39
 		}
40 40
 	}
41 41
 
42
-	protected function matchesWithDiagnosticDescription( $html, Description $mismatchDescription ) {
43
-		$internalErrors = libxml_use_internal_errors( true );
42
+	protected function matchesWithDiagnosticDescription($html, Description $mismatchDescription) {
43
+		$internalErrors = libxml_use_internal_errors(true);
44 44
 		$document = new \DOMDocument();
45 45
 
46
-		$html = $this->escapeScriptTagContents( $html );
46
+		$html = $this->escapeScriptTagContents($html);
47 47
 
48
-		if ( !@$document->loadHTML( mb_convert_encoding( $html, 'HTML-ENTITIES', 'UTF-8' ) ) ) {
49
-			$mismatchDescription->appendText( 'there was some parsing error' );
48
+		if (!@$document->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'))) {
49
+			$mismatchDescription->appendText('there was some parsing error');
50 50
 			return false;
51 51
 		}
52 52
 
53 53
 		$errors = libxml_get_errors();
54 54
 		libxml_clear_errors();
55
-		libxml_use_internal_errors( $internalErrors );
55
+		libxml_use_internal_errors($internalErrors);
56 56
 
57 57
 		$result = true;
58 58
 		/** @var \LibXMLError $error */
59
-		foreach ( $errors as $error ) {
60
-			if ( $this->isUnknownTagError( $error ) ) {
59
+		foreach ($errors as $error) {
60
+			if ($this->isUnknownTagError($error)) {
61 61
 				continue;
62 62
 			}
63 63
 
64
-			$mismatchDescription->appendText( 'there was parsing error: ' )
65
-				->appendText( trim( $error->message ) )
66
-				->appendText( ' on line ' )
67
-				->appendText( $error->line );
64
+			$mismatchDescription->appendText('there was parsing error: ')
65
+				->appendText(trim($error->message))
66
+				->appendText(' on line ')
67
+				->appendText($error->line);
68 68
 			$result = false;
69 69
 		}
70 70
 
71
-		if ( !$result ) {
71
+		if (!$result) {
72 72
 			return false;
73 73
 		}
74
-		$mismatchDescription->appendText( 'valid html piece ' );
74
+		$mismatchDescription->appendText('valid html piece ');
75 75
 
76
-		if ( $this->elementMatcher ) {
77
-			$result = $this->elementMatcher->matches( $document );
78
-			$this->elementMatcher->describeMismatch( $document, $mismatchDescription );
76
+		if ($this->elementMatcher) {
77
+			$result = $this->elementMatcher->matches($document);
78
+			$this->elementMatcher->describeMismatch($document, $mismatchDescription);
79 79
 		}
80 80
 
81
-		$mismatchDescription->appendText( "\nActual html:\n" )->appendText( $html );
81
+		$mismatchDescription->appendText("\nActual html:\n")->appendText($html);
82 82
 
83 83
 		return $result;
84 84
 	}
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	 *
89 89
 	 * @return bool
90 90
 	 */
91
-	private function isUnknownTagError( \LibXMLError $error ) {
91
+	private function isUnknownTagError(\LibXMLError $error) {
92 92
 		return $error->code === self::XML_UNKNOWN_TAG_ERROR_CODE;
93 93
 	}
94 94
 
@@ -97,10 +97,10 @@  discard block
 block discarded – undo
97 97
 	 *
98 98
 	 * @return string HTML
99 99
 	 */
100
-	private function escapeScriptTagContents( $html ) {
101
-		return preg_replace_callback( '#(<script.*>)(.*)(</script>)#isU', function ( $matches ) {
102
-			return $matches[1] . str_replace( '</', '<\/', $matches[2] ) . $matches[3];
103
-		}, $html );
100
+	private function escapeScriptTagContents($html) {
101
+		return preg_replace_callback('#(<script.*>)(.*)(</script>)#isU', function($matches) {
102
+			return $matches[1] . str_replace('</', '<\/', $matches[2]) . $matches[3];
103
+		}, $html);
104 104
 	}
105 105
 
106 106
 }
Please login to merge, or discard this patch.
src/ComplexTagMatcher.php 2 patches
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -10,214 +10,214 @@
 block discarded – undo
10 10
 
11 11
 class ComplexTagMatcher extends TagMatcher {
12 12
 
13
-	/**
14
-	 * @link http://www.xmlsoft.org/html/libxml-xmlerror.html#xmlParserErrors
15
-	 * @link https://github.com/Chronic-Dev/libxml2/blob/683f296a905710ff285c28b8644ef3a3d8be9486/include/libxml/xmlerror.h#L257
16
-	 */
17
-	const XML_UNKNOWN_TAG_ERROR_CODE = 801;
18
-
19
-	/**
20
-	 * @var string
21
-	 */
22
-	private $tagHtmlOutline;
23
-
24
-	/**
25
-	 * @var Matcher
26
-	 */
27
-	private $matcher;
28
-
29
-	/**
30
-	 * @param string $htmlOutline
31
-	 *
32
-	 * @return self
33
-	 */
34
-	public static function tagMatchingOutline( $htmlOutline ) {
35
-		return new self( $htmlOutline );
36
-	}
37
-
38
-	/**
39
-	 * @param string $tagHtmlRepresentation
40
-	 */
41
-	public function __construct( $tagHtmlRepresentation ) {
42
-		parent::__construct();
43
-
44
-		$this->tagHtmlOutline = $tagHtmlRepresentation;
45
-		$this->matcher = $this->createMatcherFromHtml( $tagHtmlRepresentation );
46
-	}
47
-
48
-	public function describeTo( Description $description ) {
49
-		$description->appendText( 'tag matching outline `' )
50
-			->appendText( $this->tagHtmlOutline )
51
-			->appendText( '` ' );
52
-	}
53
-
54
-	/**
55
-	 * @param \DOMElement $item
56
-	 * @param Description $mismatchDescription
57
-	 *
58
-	 * @return bool
59
-	 */
60
-	protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) {
61
-		if ( $this->matcher->matches( $item ) ) {
62
-			return true;
63
-		}
64
-
65
-		$mismatchDescription->appendText( 'was `' )
66
-			->appendText( $this->elementToString( $item ) )
67
-			->appendText( '`' );
68
-		return false;
69
-	}
70
-
71
-	/**
72
-	 * @param string $htmlOutline
73
-	 *
74
-	 * @return Matcher
75
-	 */
76
-	private function createMatcherFromHtml( $htmlOutline ) {
77
-		$document = $this->parseHtml( $htmlOutline );
78
-		$targetTag = $this->getSingleTagFromThe( $document );
79
-
80
-		$this->assertTagDoesNotContainChildren( $targetTag );
81
-
82
-		$attributeMatchers = $this->createAttributeMatchers( $htmlOutline, $targetTag );
83
-		$classMatchers = $this->createClassMatchers( $targetTag );
84
-
85
-		return AllOf::allOf(
86
-			new TagNameMatcher( IsEqual::equalTo( $targetTag->tagName ) ),
87
-			call_user_func_array( [ AllOf::class, 'allOf' ], $attributeMatchers ),
88
-			call_user_func_array( [ AllOf::class, 'allOf' ], $classMatchers )
89
-		);
90
-	}
91
-
92
-	/**
93
-	 * @param \LibXMLError $error
94
-	 *
95
-	 * @return bool
96
-	 */
97
-	private function isUnknownTagError( \LibXMLError $error ) {
98
-		return $error->code === self::XML_UNKNOWN_TAG_ERROR_CODE;
99
-	}
100
-
101
-	/**
102
-	 * @param string $inputHtml
103
-	 * @param string $attributeName
104
-	 *
105
-	 * @return bool
106
-	 */
107
-	private function isBooleanAttribute( $inputHtml, $attributeName ) {
108
-		$quotedName = preg_quote( $attributeName, '/' );
109
-
110
-		$attributeHasValueAssigned = preg_match( "/\b{$quotedName}\s*=/ui", $inputHtml );
111
-		return !$attributeHasValueAssigned;
112
-	}
113
-
114
-	/**
115
-	 * @param string $html
116
-	 *
117
-	 * @return \DOMDocument
118
-	 * @throws \InvalidArgumentException
119
-	 */
120
-	private function parseHtml( $html ) {
121
-		$internalErrors = libxml_use_internal_errors( true );
122
-		$document = new \DOMDocument();
123
-
124
-		if ( !@$document->loadHTML( $html ) ) {
125
-			throw new \InvalidArgumentException( "There was some parsing error of `$html`" );
126
-		}
127
-
128
-		$errors = libxml_get_errors();
129
-		libxml_clear_errors();
130
-		libxml_use_internal_errors( $internalErrors );
131
-
132
-		/** @var \LibXMLError $error */
133
-		foreach ( $errors as $error ) {
134
-			if ( $this->isUnknownTagError( $error ) ) {
135
-				continue;
136
-			}
137
-
138
-			throw new \InvalidArgumentException(
139
-				'There was parsing error: ' . trim( $error->message ) . ' on line ' . $error->line
140
-			);
141
-		}
142
-
143
-		return $document;
144
-	}
145
-
146
-	/**
147
-	 * @param \DOMDocument $document
148
-	 *
149
-	 * @return \DOMElement
150
-	 * @throws \InvalidArgumentException
151
-	 */
152
-	private function getSingleTagFromThe( \DOMDocument $document ) {
153
-		$directChildren = $document->documentElement->childNodes->item( 0 )->childNodes;
154
-
155
-		if ( $directChildren->length !== 1 ) {
156
-			throw new InvalidArgumentException(
157
-				'Expected exactly 1 tag description, got ' . $directChildren->length
158
-			);
159
-		}
160
-
161
-		return $directChildren->item( 0 );
162
-	}
163
-
164
-	private function assertTagDoesNotContainChildren( \DOMElement $targetTag ) {
165
-		if ( $targetTag->childNodes->length > 0 ) {
166
-			throw new InvalidArgumentException( 'Nested elements are not allowed' );
167
-		}
168
-	}
169
-
170
-	/**
171
-	 * @param string $inputHtml
172
-	 * @param \DOMElement $targetTag
173
-	 *
174
-	 * @return AttributeMatcher[]
175
-	 */
176
-	private function createAttributeMatchers( $inputHtml, \DOMElement $targetTag ) {
177
-		$attributeMatchers = [];
178
-		/** @var \DOMAttr $attribute */
179
-		foreach ( $targetTag->attributes as $attribute ) {
180
-			if ( $attribute->name === 'class' ) {
181
-				continue;
182
-			}
183
-
184
-			$attributeMatcher = new AttributeMatcher( IsEqual::equalTo( $attribute->name ) );
185
-			if ( !$this->isBooleanAttribute( $inputHtml, $attribute->name ) ) {
186
-				$attributeMatcher = $attributeMatcher->havingValue( IsEqual::equalTo( $attribute->value ) );
187
-			}
188
-
189
-			$attributeMatchers[] = $attributeMatcher;
190
-		}
191
-		return $attributeMatchers;
192
-	}
193
-
194
-	/**
195
-	 * @param \DOMElement $targetTag
196
-	 *
197
-	 * @return ClassMatcher[]
198
-	 */
199
-	private function createClassMatchers( \DOMElement $targetTag ) {
200
-		$classMatchers = [];
201
-		$classValue = $targetTag->getAttribute( 'class' );
202
-		foreach ( explode( ' ', $classValue ) as $expectedClass ) {
203
-			if ( $expectedClass === '' ) {
204
-				continue;
205
-			}
206
-			$classMatchers[] = new ClassMatcher( IsEqual::equalTo( $expectedClass ) );
207
-		}
208
-		return $classMatchers;
209
-	}
210
-
211
-	/**
212
-	 * @param \DOMElement $element
213
-	 *
214
-	 * @return string
215
-	 */
216
-	private function elementToString( \DOMElement $element ) {
217
-		$newDocument = new \DOMDocument();
218
-		$cloned = $element->cloneNode( true );
219
-		$newDocument->appendChild( $newDocument->importNode( $cloned, true ) );
220
-		return trim( $newDocument->saveHTML() );
221
-	}
13
+    /**
14
+     * @link http://www.xmlsoft.org/html/libxml-xmlerror.html#xmlParserErrors
15
+     * @link https://github.com/Chronic-Dev/libxml2/blob/683f296a905710ff285c28b8644ef3a3d8be9486/include/libxml/xmlerror.h#L257
16
+     */
17
+    const XML_UNKNOWN_TAG_ERROR_CODE = 801;
18
+
19
+    /**
20
+     * @var string
21
+     */
22
+    private $tagHtmlOutline;
23
+
24
+    /**
25
+     * @var Matcher
26
+     */
27
+    private $matcher;
28
+
29
+    /**
30
+     * @param string $htmlOutline
31
+     *
32
+     * @return self
33
+     */
34
+    public static function tagMatchingOutline( $htmlOutline ) {
35
+        return new self( $htmlOutline );
36
+    }
37
+
38
+    /**
39
+     * @param string $tagHtmlRepresentation
40
+     */
41
+    public function __construct( $tagHtmlRepresentation ) {
42
+        parent::__construct();
43
+
44
+        $this->tagHtmlOutline = $tagHtmlRepresentation;
45
+        $this->matcher = $this->createMatcherFromHtml( $tagHtmlRepresentation );
46
+    }
47
+
48
+    public function describeTo( Description $description ) {
49
+        $description->appendText( 'tag matching outline `' )
50
+            ->appendText( $this->tagHtmlOutline )
51
+            ->appendText( '` ' );
52
+    }
53
+
54
+    /**
55
+     * @param \DOMElement $item
56
+     * @param Description $mismatchDescription
57
+     *
58
+     * @return bool
59
+     */
60
+    protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) {
61
+        if ( $this->matcher->matches( $item ) ) {
62
+            return true;
63
+        }
64
+
65
+        $mismatchDescription->appendText( 'was `' )
66
+            ->appendText( $this->elementToString( $item ) )
67
+            ->appendText( '`' );
68
+        return false;
69
+    }
70
+
71
+    /**
72
+     * @param string $htmlOutline
73
+     *
74
+     * @return Matcher
75
+     */
76
+    private function createMatcherFromHtml( $htmlOutline ) {
77
+        $document = $this->parseHtml( $htmlOutline );
78
+        $targetTag = $this->getSingleTagFromThe( $document );
79
+
80
+        $this->assertTagDoesNotContainChildren( $targetTag );
81
+
82
+        $attributeMatchers = $this->createAttributeMatchers( $htmlOutline, $targetTag );
83
+        $classMatchers = $this->createClassMatchers( $targetTag );
84
+
85
+        return AllOf::allOf(
86
+            new TagNameMatcher( IsEqual::equalTo( $targetTag->tagName ) ),
87
+            call_user_func_array( [ AllOf::class, 'allOf' ], $attributeMatchers ),
88
+            call_user_func_array( [ AllOf::class, 'allOf' ], $classMatchers )
89
+        );
90
+    }
91
+
92
+    /**
93
+     * @param \LibXMLError $error
94
+     *
95
+     * @return bool
96
+     */
97
+    private function isUnknownTagError( \LibXMLError $error ) {
98
+        return $error->code === self::XML_UNKNOWN_TAG_ERROR_CODE;
99
+    }
100
+
101
+    /**
102
+     * @param string $inputHtml
103
+     * @param string $attributeName
104
+     *
105
+     * @return bool
106
+     */
107
+    private function isBooleanAttribute( $inputHtml, $attributeName ) {
108
+        $quotedName = preg_quote( $attributeName, '/' );
109
+
110
+        $attributeHasValueAssigned = preg_match( "/\b{$quotedName}\s*=/ui", $inputHtml );
111
+        return !$attributeHasValueAssigned;
112
+    }
113
+
114
+    /**
115
+     * @param string $html
116
+     *
117
+     * @return \DOMDocument
118
+     * @throws \InvalidArgumentException
119
+     */
120
+    private function parseHtml( $html ) {
121
+        $internalErrors = libxml_use_internal_errors( true );
122
+        $document = new \DOMDocument();
123
+
124
+        if ( !@$document->loadHTML( $html ) ) {
125
+            throw new \InvalidArgumentException( "There was some parsing error of `$html`" );
126
+        }
127
+
128
+        $errors = libxml_get_errors();
129
+        libxml_clear_errors();
130
+        libxml_use_internal_errors( $internalErrors );
131
+
132
+        /** @var \LibXMLError $error */
133
+        foreach ( $errors as $error ) {
134
+            if ( $this->isUnknownTagError( $error ) ) {
135
+                continue;
136
+            }
137
+
138
+            throw new \InvalidArgumentException(
139
+                'There was parsing error: ' . trim( $error->message ) . ' on line ' . $error->line
140
+            );
141
+        }
142
+
143
+        return $document;
144
+    }
145
+
146
+    /**
147
+     * @param \DOMDocument $document
148
+     *
149
+     * @return \DOMElement
150
+     * @throws \InvalidArgumentException
151
+     */
152
+    private function getSingleTagFromThe( \DOMDocument $document ) {
153
+        $directChildren = $document->documentElement->childNodes->item( 0 )->childNodes;
154
+
155
+        if ( $directChildren->length !== 1 ) {
156
+            throw new InvalidArgumentException(
157
+                'Expected exactly 1 tag description, got ' . $directChildren->length
158
+            );
159
+        }
160
+
161
+        return $directChildren->item( 0 );
162
+    }
163
+
164
+    private function assertTagDoesNotContainChildren( \DOMElement $targetTag ) {
165
+        if ( $targetTag->childNodes->length > 0 ) {
166
+            throw new InvalidArgumentException( 'Nested elements are not allowed' );
167
+        }
168
+    }
169
+
170
+    /**
171
+     * @param string $inputHtml
172
+     * @param \DOMElement $targetTag
173
+     *
174
+     * @return AttributeMatcher[]
175
+     */
176
+    private function createAttributeMatchers( $inputHtml, \DOMElement $targetTag ) {
177
+        $attributeMatchers = [];
178
+        /** @var \DOMAttr $attribute */
179
+        foreach ( $targetTag->attributes as $attribute ) {
180
+            if ( $attribute->name === 'class' ) {
181
+                continue;
182
+            }
183
+
184
+            $attributeMatcher = new AttributeMatcher( IsEqual::equalTo( $attribute->name ) );
185
+            if ( !$this->isBooleanAttribute( $inputHtml, $attribute->name ) ) {
186
+                $attributeMatcher = $attributeMatcher->havingValue( IsEqual::equalTo( $attribute->value ) );
187
+            }
188
+
189
+            $attributeMatchers[] = $attributeMatcher;
190
+        }
191
+        return $attributeMatchers;
192
+    }
193
+
194
+    /**
195
+     * @param \DOMElement $targetTag
196
+     *
197
+     * @return ClassMatcher[]
198
+     */
199
+    private function createClassMatchers( \DOMElement $targetTag ) {
200
+        $classMatchers = [];
201
+        $classValue = $targetTag->getAttribute( 'class' );
202
+        foreach ( explode( ' ', $classValue ) as $expectedClass ) {
203
+            if ( $expectedClass === '' ) {
204
+                continue;
205
+            }
206
+            $classMatchers[] = new ClassMatcher( IsEqual::equalTo( $expectedClass ) );
207
+        }
208
+        return $classMatchers;
209
+    }
210
+
211
+    /**
212
+     * @param \DOMElement $element
213
+     *
214
+     * @return string
215
+     */
216
+    private function elementToString( \DOMElement $element ) {
217
+        $newDocument = new \DOMDocument();
218
+        $cloned = $element->cloneNode( true );
219
+        $newDocument->appendChild( $newDocument->importNode( $cloned, true ) );
220
+        return trim( $newDocument->saveHTML() );
221
+    }
222 222
 
223 223
 }
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -31,24 +31,24 @@  discard block
 block discarded – undo
31 31
 	 *
32 32
 	 * @return self
33 33
 	 */
34
-	public static function tagMatchingOutline( $htmlOutline ) {
35
-		return new self( $htmlOutline );
34
+	public static function tagMatchingOutline($htmlOutline) {
35
+		return new self($htmlOutline);
36 36
 	}
37 37
 
38 38
 	/**
39 39
 	 * @param string $tagHtmlRepresentation
40 40
 	 */
41
-	public function __construct( $tagHtmlRepresentation ) {
41
+	public function __construct($tagHtmlRepresentation) {
42 42
 		parent::__construct();
43 43
 
44 44
 		$this->tagHtmlOutline = $tagHtmlRepresentation;
45
-		$this->matcher = $this->createMatcherFromHtml( $tagHtmlRepresentation );
45
+		$this->matcher = $this->createMatcherFromHtml($tagHtmlRepresentation);
46 46
 	}
47 47
 
48
-	public function describeTo( Description $description ) {
49
-		$description->appendText( 'tag matching outline `' )
50
-			->appendText( $this->tagHtmlOutline )
51
-			->appendText( '` ' );
48
+	public function describeTo(Description $description) {
49
+		$description->appendText('tag matching outline `')
50
+			->appendText($this->tagHtmlOutline)
51
+			->appendText('` ');
52 52
 	}
53 53
 
54 54
 	/**
@@ -57,14 +57,14 @@  discard block
 block discarded – undo
57 57
 	 *
58 58
 	 * @return bool
59 59
 	 */
60
-	protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) {
61
-		if ( $this->matcher->matches( $item ) ) {
60
+	protected function matchesSafelyWithDiagnosticDescription($item, Description $mismatchDescription) {
61
+		if ($this->matcher->matches($item)) {
62 62
 			return true;
63 63
 		}
64 64
 
65
-		$mismatchDescription->appendText( 'was `' )
66
-			->appendText( $this->elementToString( $item ) )
67
-			->appendText( '`' );
65
+		$mismatchDescription->appendText('was `')
66
+			->appendText($this->elementToString($item))
67
+			->appendText('`');
68 68
 		return false;
69 69
 	}
70 70
 
@@ -73,19 +73,19 @@  discard block
 block discarded – undo
73 73
 	 *
74 74
 	 * @return Matcher
75 75
 	 */
76
-	private function createMatcherFromHtml( $htmlOutline ) {
77
-		$document = $this->parseHtml( $htmlOutline );
78
-		$targetTag = $this->getSingleTagFromThe( $document );
76
+	private function createMatcherFromHtml($htmlOutline) {
77
+		$document = $this->parseHtml($htmlOutline);
78
+		$targetTag = $this->getSingleTagFromThe($document);
79 79
 
80
-		$this->assertTagDoesNotContainChildren( $targetTag );
80
+		$this->assertTagDoesNotContainChildren($targetTag);
81 81
 
82
-		$attributeMatchers = $this->createAttributeMatchers( $htmlOutline, $targetTag );
83
-		$classMatchers = $this->createClassMatchers( $targetTag );
82
+		$attributeMatchers = $this->createAttributeMatchers($htmlOutline, $targetTag);
83
+		$classMatchers = $this->createClassMatchers($targetTag);
84 84
 
85 85
 		return AllOf::allOf(
86
-			new TagNameMatcher( IsEqual::equalTo( $targetTag->tagName ) ),
87
-			call_user_func_array( [ AllOf::class, 'allOf' ], $attributeMatchers ),
88
-			call_user_func_array( [ AllOf::class, 'allOf' ], $classMatchers )
86
+			new TagNameMatcher(IsEqual::equalTo($targetTag->tagName)),
87
+			call_user_func_array([AllOf::class, 'allOf'], $attributeMatchers),
88
+			call_user_func_array([AllOf::class, 'allOf'], $classMatchers)
89 89
 		);
90 90
 	}
91 91
 
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	 *
95 95
 	 * @return bool
96 96
 	 */
97
-	private function isUnknownTagError( \LibXMLError $error ) {
97
+	private function isUnknownTagError(\LibXMLError $error) {
98 98
 		return $error->code === self::XML_UNKNOWN_TAG_ERROR_CODE;
99 99
 	}
100 100
 
@@ -104,10 +104,10 @@  discard block
 block discarded – undo
104 104
 	 *
105 105
 	 * @return bool
106 106
 	 */
107
-	private function isBooleanAttribute( $inputHtml, $attributeName ) {
108
-		$quotedName = preg_quote( $attributeName, '/' );
107
+	private function isBooleanAttribute($inputHtml, $attributeName) {
108
+		$quotedName = preg_quote($attributeName, '/');
109 109
 
110
-		$attributeHasValueAssigned = preg_match( "/\b{$quotedName}\s*=/ui", $inputHtml );
110
+		$attributeHasValueAssigned = preg_match("/\b{$quotedName}\s*=/ui", $inputHtml);
111 111
 		return !$attributeHasValueAssigned;
112 112
 	}
113 113
 
@@ -117,26 +117,26 @@  discard block
 block discarded – undo
117 117
 	 * @return \DOMDocument
118 118
 	 * @throws \InvalidArgumentException
119 119
 	 */
120
-	private function parseHtml( $html ) {
121
-		$internalErrors = libxml_use_internal_errors( true );
120
+	private function parseHtml($html) {
121
+		$internalErrors = libxml_use_internal_errors(true);
122 122
 		$document = new \DOMDocument();
123 123
 
124
-		if ( !@$document->loadHTML( $html ) ) {
125
-			throw new \InvalidArgumentException( "There was some parsing error of `$html`" );
124
+		if (!@$document->loadHTML($html)) {
125
+			throw new \InvalidArgumentException("There was some parsing error of `$html`");
126 126
 		}
127 127
 
128 128
 		$errors = libxml_get_errors();
129 129
 		libxml_clear_errors();
130
-		libxml_use_internal_errors( $internalErrors );
130
+		libxml_use_internal_errors($internalErrors);
131 131
 
132 132
 		/** @var \LibXMLError $error */
133
-		foreach ( $errors as $error ) {
134
-			if ( $this->isUnknownTagError( $error ) ) {
133
+		foreach ($errors as $error) {
134
+			if ($this->isUnknownTagError($error)) {
135 135
 				continue;
136 136
 			}
137 137
 
138 138
 			throw new \InvalidArgumentException(
139
-				'There was parsing error: ' . trim( $error->message ) . ' on line ' . $error->line
139
+				'There was parsing error: ' . trim($error->message) . ' on line ' . $error->line
140 140
 			);
141 141
 		}
142 142
 
@@ -149,21 +149,21 @@  discard block
 block discarded – undo
149 149
 	 * @return \DOMElement
150 150
 	 * @throws \InvalidArgumentException
151 151
 	 */
152
-	private function getSingleTagFromThe( \DOMDocument $document ) {
153
-		$directChildren = $document->documentElement->childNodes->item( 0 )->childNodes;
152
+	private function getSingleTagFromThe(\DOMDocument $document) {
153
+		$directChildren = $document->documentElement->childNodes->item(0)->childNodes;
154 154
 
155
-		if ( $directChildren->length !== 1 ) {
155
+		if ($directChildren->length !== 1) {
156 156
 			throw new InvalidArgumentException(
157 157
 				'Expected exactly 1 tag description, got ' . $directChildren->length
158 158
 			);
159 159
 		}
160 160
 
161
-		return $directChildren->item( 0 );
161
+		return $directChildren->item(0);
162 162
 	}
163 163
 
164
-	private function assertTagDoesNotContainChildren( \DOMElement $targetTag ) {
165
-		if ( $targetTag->childNodes->length > 0 ) {
166
-			throw new InvalidArgumentException( 'Nested elements are not allowed' );
164
+	private function assertTagDoesNotContainChildren(\DOMElement $targetTag) {
165
+		if ($targetTag->childNodes->length > 0) {
166
+			throw new InvalidArgumentException('Nested elements are not allowed');
167 167
 		}
168 168
 	}
169 169
 
@@ -173,17 +173,17 @@  discard block
 block discarded – undo
173 173
 	 *
174 174
 	 * @return AttributeMatcher[]
175 175
 	 */
176
-	private function createAttributeMatchers( $inputHtml, \DOMElement $targetTag ) {
176
+	private function createAttributeMatchers($inputHtml, \DOMElement $targetTag) {
177 177
 		$attributeMatchers = [];
178 178
 		/** @var \DOMAttr $attribute */
179
-		foreach ( $targetTag->attributes as $attribute ) {
180
-			if ( $attribute->name === 'class' ) {
179
+		foreach ($targetTag->attributes as $attribute) {
180
+			if ($attribute->name === 'class') {
181 181
 				continue;
182 182
 			}
183 183
 
184
-			$attributeMatcher = new AttributeMatcher( IsEqual::equalTo( $attribute->name ) );
185
-			if ( !$this->isBooleanAttribute( $inputHtml, $attribute->name ) ) {
186
-				$attributeMatcher = $attributeMatcher->havingValue( IsEqual::equalTo( $attribute->value ) );
184
+			$attributeMatcher = new AttributeMatcher(IsEqual::equalTo($attribute->name));
185
+			if (!$this->isBooleanAttribute($inputHtml, $attribute->name)) {
186
+				$attributeMatcher = $attributeMatcher->havingValue(IsEqual::equalTo($attribute->value));
187 187
 			}
188 188
 
189 189
 			$attributeMatchers[] = $attributeMatcher;
@@ -196,14 +196,14 @@  discard block
 block discarded – undo
196 196
 	 *
197 197
 	 * @return ClassMatcher[]
198 198
 	 */
199
-	private function createClassMatchers( \DOMElement $targetTag ) {
199
+	private function createClassMatchers(\DOMElement $targetTag) {
200 200
 		$classMatchers = [];
201
-		$classValue = $targetTag->getAttribute( 'class' );
202
-		foreach ( explode( ' ', $classValue ) as $expectedClass ) {
203
-			if ( $expectedClass === '' ) {
201
+		$classValue = $targetTag->getAttribute('class');
202
+		foreach (explode(' ', $classValue) as $expectedClass) {
203
+			if ($expectedClass === '') {
204 204
 				continue;
205 205
 			}
206
-			$classMatchers[] = new ClassMatcher( IsEqual::equalTo( $expectedClass ) );
206
+			$classMatchers[] = new ClassMatcher(IsEqual::equalTo($expectedClass));
207 207
 		}
208 208
 		return $classMatchers;
209 209
 	}
@@ -213,11 +213,11 @@  discard block
 block discarded – undo
213 213
 	 *
214 214
 	 * @return string
215 215
 	 */
216
-	private function elementToString( \DOMElement $element ) {
216
+	private function elementToString(\DOMElement $element) {
217 217
 		$newDocument = new \DOMDocument();
218
-		$cloned = $element->cloneNode( true );
219
-		$newDocument->appendChild( $newDocument->importNode( $cloned, true ) );
220
-		return trim( $newDocument->saveHTML() );
218
+		$cloned = $element->cloneNode(true);
219
+		$newDocument->appendChild($newDocument->importNode($cloned, true));
220
+		return trim($newDocument->saveHTML());
221 221
 	}
222 222
 
223 223
 }
Please login to merge, or discard this patch.