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