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 (#2)
by no
02:18
created
src/ComplexTagMatcher.php 2 patches
Indentation   +210 added lines, -210 removed lines patch added patch discarded remove patch
@@ -10,215 +10,215 @@
 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
-		// phpcs:ignore Generic.PHP.NoSilencedErrors
125
-		if ( !@$document->loadHTML( $html ) ) {
126
-			throw new \InvalidArgumentException( "There was some parsing error of `$html`" );
127
-		}
128
-
129
-		$errors = libxml_get_errors();
130
-		libxml_clear_errors();
131
-		libxml_use_internal_errors( $internalErrors );
132
-
133
-		/** @var \LibXMLError $error */
134
-		foreach ( $errors as $error ) {
135
-			if ( $this->isUnknownTagError( $error ) ) {
136
-				continue;
137
-			}
138
-
139
-			throw new \InvalidArgumentException(
140
-				'There was parsing error: ' . trim( $error->message ) . ' on line ' . $error->line
141
-			);
142
-		}
143
-
144
-		return $document;
145
-	}
146
-
147
-	/**
148
-	 * @param \DOMDocument $document
149
-	 *
150
-	 * @return \DOMElement
151
-	 * @throws \InvalidArgumentException
152
-	 */
153
-	private function getSingleTagFromThe( \DOMDocument $document ) {
154
-		$directChildren = $document->documentElement->childNodes->item( 0 )->childNodes;
155
-
156
-		if ( $directChildren->length !== 1 ) {
157
-			throw new InvalidArgumentException(
158
-				'Expected exactly 1 tag description, got ' . $directChildren->length
159
-			);
160
-		}
161
-
162
-		return $directChildren->item( 0 );
163
-	}
164
-
165
-	private function assertTagDoesNotContainChildren( \DOMElement $targetTag ) {
166
-		if ( $targetTag->childNodes->length > 0 ) {
167
-			throw new InvalidArgumentException( 'Nested elements are not allowed' );
168
-		}
169
-	}
170
-
171
-	/**
172
-	 * @param string $inputHtml
173
-	 * @param \DOMElement $targetTag
174
-	 *
175
-	 * @return AttributeMatcher[]
176
-	 */
177
-	private function createAttributeMatchers( $inputHtml, \DOMElement $targetTag ) {
178
-		$attributeMatchers = [];
179
-		/** @var \DOMAttr $attribute */
180
-		foreach ( $targetTag->attributes as $attribute ) {
181
-			if ( $attribute->name === 'class' ) {
182
-				continue;
183
-			}
184
-
185
-			$attributeMatcher = new AttributeMatcher( IsEqual::equalTo( $attribute->name ) );
186
-			if ( !$this->isBooleanAttribute( $inputHtml, $attribute->name ) ) {
187
-				$attributeMatcher = $attributeMatcher->havingValue( IsEqual::equalTo( $attribute->value ) );
188
-			}
189
-
190
-			$attributeMatchers[] = $attributeMatcher;
191
-		}
192
-		return $attributeMatchers;
193
-	}
194
-
195
-	/**
196
-	 * @param \DOMElement $targetTag
197
-	 *
198
-	 * @return ClassMatcher[]
199
-	 */
200
-	private function createClassMatchers( \DOMElement $targetTag ) {
201
-		$classMatchers = [];
202
-		$classValue = $targetTag->getAttribute( 'class' );
203
-		foreach ( explode( ' ', $classValue ) as $expectedClass ) {
204
-			if ( $expectedClass === '' ) {
205
-				continue;
206
-			}
207
-			$classMatchers[] = new ClassMatcher( IsEqual::equalTo( $expectedClass ) );
208
-		}
209
-		return $classMatchers;
210
-	}
211
-
212
-	/**
213
-	 * @param \DOMElement $element
214
-	 *
215
-	 * @return string
216
-	 */
217
-	private function elementToString( \DOMElement $element ) {
218
-		$newDocument = new \DOMDocument();
219
-		$cloned = $element->cloneNode( true );
220
-		$newDocument->appendChild( $newDocument->importNode( $cloned, true ) );
221
-		return trim( $newDocument->saveHTML() );
222
-	}
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
+        // phpcs:ignore Generic.PHP.NoSilencedErrors
125
+        if ( !@$document->loadHTML( $html ) ) {
126
+            throw new \InvalidArgumentException( "There was some parsing error of `$html`" );
127
+        }
128
+
129
+        $errors = libxml_get_errors();
130
+        libxml_clear_errors();
131
+        libxml_use_internal_errors( $internalErrors );
132
+
133
+        /** @var \LibXMLError $error */
134
+        foreach ( $errors as $error ) {
135
+            if ( $this->isUnknownTagError( $error ) ) {
136
+                continue;
137
+            }
138
+
139
+            throw new \InvalidArgumentException(
140
+                'There was parsing error: ' . trim( $error->message ) . ' on line ' . $error->line
141
+            );
142
+        }
143
+
144
+        return $document;
145
+    }
146
+
147
+    /**
148
+     * @param \DOMDocument $document
149
+     *
150
+     * @return \DOMElement
151
+     * @throws \InvalidArgumentException
152
+     */
153
+    private function getSingleTagFromThe( \DOMDocument $document ) {
154
+        $directChildren = $document->documentElement->childNodes->item( 0 )->childNodes;
155
+
156
+        if ( $directChildren->length !== 1 ) {
157
+            throw new InvalidArgumentException(
158
+                'Expected exactly 1 tag description, got ' . $directChildren->length
159
+            );
160
+        }
161
+
162
+        return $directChildren->item( 0 );
163
+    }
164
+
165
+    private function assertTagDoesNotContainChildren( \DOMElement $targetTag ) {
166
+        if ( $targetTag->childNodes->length > 0 ) {
167
+            throw new InvalidArgumentException( 'Nested elements are not allowed' );
168
+        }
169
+    }
170
+
171
+    /**
172
+     * @param string $inputHtml
173
+     * @param \DOMElement $targetTag
174
+     *
175
+     * @return AttributeMatcher[]
176
+     */
177
+    private function createAttributeMatchers( $inputHtml, \DOMElement $targetTag ) {
178
+        $attributeMatchers = [];
179
+        /** @var \DOMAttr $attribute */
180
+        foreach ( $targetTag->attributes as $attribute ) {
181
+            if ( $attribute->name === 'class' ) {
182
+                continue;
183
+            }
184
+
185
+            $attributeMatcher = new AttributeMatcher( IsEqual::equalTo( $attribute->name ) );
186
+            if ( !$this->isBooleanAttribute( $inputHtml, $attribute->name ) ) {
187
+                $attributeMatcher = $attributeMatcher->havingValue( IsEqual::equalTo( $attribute->value ) );
188
+            }
189
+
190
+            $attributeMatchers[] = $attributeMatcher;
191
+        }
192
+        return $attributeMatchers;
193
+    }
194
+
195
+    /**
196
+     * @param \DOMElement $targetTag
197
+     *
198
+     * @return ClassMatcher[]
199
+     */
200
+    private function createClassMatchers( \DOMElement $targetTag ) {
201
+        $classMatchers = [];
202
+        $classValue = $targetTag->getAttribute( 'class' );
203
+        foreach ( explode( ' ', $classValue ) as $expectedClass ) {
204
+            if ( $expectedClass === '' ) {
205
+                continue;
206
+            }
207
+            $classMatchers[] = new ClassMatcher( IsEqual::equalTo( $expectedClass ) );
208
+        }
209
+        return $classMatchers;
210
+    }
211
+
212
+    /**
213
+     * @param \DOMElement $element
214
+     *
215
+     * @return string
216
+     */
217
+    private function elementToString( \DOMElement $element ) {
218
+        $newDocument = new \DOMDocument();
219
+        $cloned = $element->cloneNode( true );
220
+        $newDocument->appendChild( $newDocument->importNode( $cloned, true ) );
221
+        return trim( $newDocument->saveHTML() );
222
+    }
223 223
 
224 224
 }
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,27 +117,27 @@  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 124
 		// phpcs:ignore Generic.PHP.NoSilencedErrors
125
-		if ( !@$document->loadHTML( $html ) ) {
126
-			throw new \InvalidArgumentException( "There was some parsing error of `$html`" );
125
+		if (!@$document->loadHTML($html)) {
126
+			throw new \InvalidArgumentException("There was some parsing error of `$html`");
127 127
 		}
128 128
 
129 129
 		$errors = libxml_get_errors();
130 130
 		libxml_clear_errors();
131
-		libxml_use_internal_errors( $internalErrors );
131
+		libxml_use_internal_errors($internalErrors);
132 132
 
133 133
 		/** @var \LibXMLError $error */
134
-		foreach ( $errors as $error ) {
135
-			if ( $this->isUnknownTagError( $error ) ) {
134
+		foreach ($errors as $error) {
135
+			if ($this->isUnknownTagError($error)) {
136 136
 				continue;
137 137
 			}
138 138
 
139 139
 			throw new \InvalidArgumentException(
140
-				'There was parsing error: ' . trim( $error->message ) . ' on line ' . $error->line
140
+				'There was parsing error: ' . trim($error->message) . ' on line ' . $error->line
141 141
 			);
142 142
 		}
143 143
 
@@ -150,21 +150,21 @@  discard block
 block discarded – undo
150 150
 	 * @return \DOMElement
151 151
 	 * @throws \InvalidArgumentException
152 152
 	 */
153
-	private function getSingleTagFromThe( \DOMDocument $document ) {
154
-		$directChildren = $document->documentElement->childNodes->item( 0 )->childNodes;
153
+	private function getSingleTagFromThe(\DOMDocument $document) {
154
+		$directChildren = $document->documentElement->childNodes->item(0)->childNodes;
155 155
 
156
-		if ( $directChildren->length !== 1 ) {
156
+		if ($directChildren->length !== 1) {
157 157
 			throw new InvalidArgumentException(
158 158
 				'Expected exactly 1 tag description, got ' . $directChildren->length
159 159
 			);
160 160
 		}
161 161
 
162
-		return $directChildren->item( 0 );
162
+		return $directChildren->item(0);
163 163
 	}
164 164
 
165
-	private function assertTagDoesNotContainChildren( \DOMElement $targetTag ) {
166
-		if ( $targetTag->childNodes->length > 0 ) {
167
-			throw new InvalidArgumentException( 'Nested elements are not allowed' );
165
+	private function assertTagDoesNotContainChildren(\DOMElement $targetTag) {
166
+		if ($targetTag->childNodes->length > 0) {
167
+			throw new InvalidArgumentException('Nested elements are not allowed');
168 168
 		}
169 169
 	}
170 170
 
@@ -174,17 +174,17 @@  discard block
 block discarded – undo
174 174
 	 *
175 175
 	 * @return AttributeMatcher[]
176 176
 	 */
177
-	private function createAttributeMatchers( $inputHtml, \DOMElement $targetTag ) {
177
+	private function createAttributeMatchers($inputHtml, \DOMElement $targetTag) {
178 178
 		$attributeMatchers = [];
179 179
 		/** @var \DOMAttr $attribute */
180
-		foreach ( $targetTag->attributes as $attribute ) {
181
-			if ( $attribute->name === 'class' ) {
180
+		foreach ($targetTag->attributes as $attribute) {
181
+			if ($attribute->name === 'class') {
182 182
 				continue;
183 183
 			}
184 184
 
185
-			$attributeMatcher = new AttributeMatcher( IsEqual::equalTo( $attribute->name ) );
186
-			if ( !$this->isBooleanAttribute( $inputHtml, $attribute->name ) ) {
187
-				$attributeMatcher = $attributeMatcher->havingValue( IsEqual::equalTo( $attribute->value ) );
185
+			$attributeMatcher = new AttributeMatcher(IsEqual::equalTo($attribute->name));
186
+			if (!$this->isBooleanAttribute($inputHtml, $attribute->name)) {
187
+				$attributeMatcher = $attributeMatcher->havingValue(IsEqual::equalTo($attribute->value));
188 188
 			}
189 189
 
190 190
 			$attributeMatchers[] = $attributeMatcher;
@@ -197,14 +197,14 @@  discard block
 block discarded – undo
197 197
 	 *
198 198
 	 * @return ClassMatcher[]
199 199
 	 */
200
-	private function createClassMatchers( \DOMElement $targetTag ) {
200
+	private function createClassMatchers(\DOMElement $targetTag) {
201 201
 		$classMatchers = [];
202
-		$classValue = $targetTag->getAttribute( 'class' );
203
-		foreach ( explode( ' ', $classValue ) as $expectedClass ) {
204
-			if ( $expectedClass === '' ) {
202
+		$classValue = $targetTag->getAttribute('class');
203
+		foreach (explode(' ', $classValue) as $expectedClass) {
204
+			if ($expectedClass === '') {
205 205
 				continue;
206 206
 			}
207
-			$classMatchers[] = new ClassMatcher( IsEqual::equalTo( $expectedClass ) );
207
+			$classMatchers[] = new ClassMatcher(IsEqual::equalTo($expectedClass));
208 208
 		}
209 209
 		return $classMatchers;
210 210
 	}
@@ -214,11 +214,11 @@  discard block
 block discarded – undo
214 214
 	 *
215 215
 	 * @return string
216 216
 	 */
217
-	private function elementToString( \DOMElement $element ) {
217
+	private function elementToString(\DOMElement $element) {
218 218
 		$newDocument = new \DOMDocument();
219
-		$cloned = $element->cloneNode( true );
220
-		$newDocument->appendChild( $newDocument->importNode( $cloned, true ) );
221
-		return trim( $newDocument->saveHTML() );
219
+		$cloned = $element->cloneNode(true);
220
+		$newDocument->appendChild($newDocument->importNode($cloned, true));
221
+		return trim($newDocument->saveHTML());
222 222
 	}
223 223
 
224 224
 }
Please login to merge, or discard this patch.
src/StringContainsIgnoringWhiteSpace.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -6,37 +6,37 @@
 block discarded – undo
6 6
 
7 7
 class StringContainsIgnoringWhiteSpace extends SubstringMatcher {
8 8
 
9
-	/**
10
-	 * Matches if value is a string that contains $substring consider all whitespace as single space
11
-	 *
12
-	 * @param string $substring
13
-	 *
14
-	 * @return self
15
-	 */
16
-	public static function containsStringIgnoringWhiteSpace( $substring ) {
17
-		return new self( $substring );
18
-	}
19
-
20
-	/**
21
-	 * @param string $item
22
-	 *
23
-	 * @return bool
24
-	 */
25
-	protected function evalSubstringOf( $item ) {
26
-		return strpos( $this->stripSpace( $item ), $this->stripSpace( $this->_substring ) ) !== false;
27
-	}
28
-
29
-	protected function relationship() {
30
-		return 'containing ignoring whitespace';
31
-	}
32
-
33
-	/**
34
-	 * @param string $string
35
-	 *
36
-	 * @return string
37
-	 */
38
-	private function stripSpace( $string ) {
39
-		return trim( preg_replace( '/\s+/', ' ', $string ) );
40
-	}
9
+    /**
10
+     * Matches if value is a string that contains $substring consider all whitespace as single space
11
+     *
12
+     * @param string $substring
13
+     *
14
+     * @return self
15
+     */
16
+    public static function containsStringIgnoringWhiteSpace( $substring ) {
17
+        return new self( $substring );
18
+    }
19
+
20
+    /**
21
+     * @param string $item
22
+     *
23
+     * @return bool
24
+     */
25
+    protected function evalSubstringOf( $item ) {
26
+        return strpos( $this->stripSpace( $item ), $this->stripSpace( $this->_substring ) ) !== false;
27
+    }
28
+
29
+    protected function relationship() {
30
+        return 'containing ignoring whitespace';
31
+    }
32
+
33
+    /**
34
+     * @param string $string
35
+     *
36
+     * @return string
37
+     */
38
+    private function stripSpace( $string ) {
39
+        return trim( preg_replace( '/\s+/', ' ', $string ) );
40
+    }
41 41
 
42 42
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -13,8 +13,8 @@  discard block
 block discarded – undo
13 13
 	 *
14 14
 	 * @return self
15 15
 	 */
16
-	public static function containsStringIgnoringWhiteSpace( $substring ) {
17
-		return new self( $substring );
16
+	public static function containsStringIgnoringWhiteSpace($substring) {
17
+		return new self($substring);
18 18
 	}
19 19
 
20 20
 	/**
@@ -22,8 +22,8 @@  discard block
 block discarded – undo
22 22
 	 *
23 23
 	 * @return bool
24 24
 	 */
25
-	protected function evalSubstringOf( $item ) {
26
-		return strpos( $this->stripSpace( $item ), $this->stripSpace( $this->_substring ) ) !== false;
25
+	protected function evalSubstringOf($item) {
26
+		return strpos($this->stripSpace($item), $this->stripSpace($this->_substring)) !== false;
27 27
 	}
28 28
 
29 29
 	protected function relationship() {
@@ -35,8 +35,8 @@  discard block
 block discarded – undo
35 35
 	 *
36 36
 	 * @return string
37 37
 	 */
38
-	private function stripSpace( $string ) {
39
-		return trim( preg_replace( '/\s+/', ' ', $string ) );
38
+	private function stripSpace($string) {
39
+		return trim(preg_replace('/\s+/', ' ', $string));
40 40
 	}
41 41
 
42 42
 }
Please login to merge, or discard this patch.
src/functions.php 2 patches
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -3,100 +3,100 @@
 block discarded – undo
3 3
 use Hamcrest\Matcher;
4 4
 
5 5
 if ( !function_exists( 'htmlPiece' ) ) {
6
-	/**
7
-	 * @param Matcher|null $elementMatcher
8
-	 *
9
-	 * @return \WMDE\HamcrestHtml\HtmlMatcher
10
-	 */
11
-	function htmlPiece( Matcher $elementMatcher = null ) {
12
-		return \WMDE\HamcrestHtml\HtmlMatcher::htmlPiece( $elementMatcher );
13
-	}
6
+    /**
7
+     * @param Matcher|null $elementMatcher
8
+     *
9
+     * @return \WMDE\HamcrestHtml\HtmlMatcher
10
+     */
11
+    function htmlPiece( Matcher $elementMatcher = null ) {
12
+        return \WMDE\HamcrestHtml\HtmlMatcher::htmlPiece( $elementMatcher );
13
+    }
14 14
 }
15 15
 
16 16
 if ( !function_exists( 'havingRootElement' ) ) {
17
-	function havingRootElement( Matcher $matcher = null ) {
18
-		return \WMDE\HamcrestHtml\RootElementMatcher::havingRootElement( $matcher );
19
-	}
17
+    function havingRootElement( Matcher $matcher = null ) {
18
+        return \WMDE\HamcrestHtml\RootElementMatcher::havingRootElement( $matcher );
19
+    }
20 20
 }
21 21
 
22 22
 if ( !function_exists( 'havingDirectChild' ) ) {
23
-	function havingDirectChild( Matcher $elementMatcher = null ) {
24
-		return \WMDE\HamcrestHtml\DirectChildElementMatcher::havingDirectChild( $elementMatcher );
25
-	}
23
+    function havingDirectChild( Matcher $elementMatcher = null ) {
24
+        return \WMDE\HamcrestHtml\DirectChildElementMatcher::havingDirectChild( $elementMatcher );
25
+    }
26 26
 }
27 27
 
28 28
 if ( !function_exists( 'havingChild' ) ) {
29
-	function havingChild( Matcher $elementMatcher = null ) {
30
-		return \WMDE\HamcrestHtml\ChildElementMatcher::havingChild( $elementMatcher );
31
-	}
29
+    function havingChild( Matcher $elementMatcher = null ) {
30
+        return \WMDE\HamcrestHtml\ChildElementMatcher::havingChild( $elementMatcher );
31
+    }
32 32
 }
33 33
 
34 34
 if ( !function_exists( 'withTagName' ) ) {
35
-	/**
36
-	 * @param Matcher|string $tagName
37
-	 *
38
-	 * @return \WMDE\HamcrestHtml\TagNameMatcher
39
-	 */
40
-	function withTagName( $tagName ) {
41
-		return \WMDE\HamcrestHtml\TagNameMatcher::withTagName( $tagName );
42
-	}
35
+    /**
36
+     * @param Matcher|string $tagName
37
+     *
38
+     * @return \WMDE\HamcrestHtml\TagNameMatcher
39
+     */
40
+    function withTagName( $tagName ) {
41
+        return \WMDE\HamcrestHtml\TagNameMatcher::withTagName( $tagName );
42
+    }
43 43
 }
44 44
 
45 45
 if ( !function_exists( 'withAttribute' ) ) {
46
-	/**
47
-	 * @param Matcher|string $attributeName
48
-	 *
49
-	 * @return \WMDE\HamcrestHtml\AttributeMatcher
50
-	 */
51
-	function withAttribute( $attributeName ) {
52
-		return \WMDE\HamcrestHtml\AttributeMatcher::withAttribute( $attributeName );
53
-	}
46
+    /**
47
+     * @param Matcher|string $attributeName
48
+     *
49
+     * @return \WMDE\HamcrestHtml\AttributeMatcher
50
+     */
51
+    function withAttribute( $attributeName ) {
52
+        return \WMDE\HamcrestHtml\AttributeMatcher::withAttribute( $attributeName );
53
+    }
54 54
 }
55 55
 
56 56
 if ( !function_exists( 'withClass' ) ) {
57
-	/**
58
-	 * @param Matcher|string $class
59
-	 *
60
-	 * @return \WMDE\HamcrestHtml\ClassMatcher
61
-	 */
62
-	function withClass( $class ) {
63
-		// TODO don't allow to call with empty string
57
+    /**
58
+     * @param Matcher|string $class
59
+     *
60
+     * @return \WMDE\HamcrestHtml\ClassMatcher
61
+     */
62
+    function withClass( $class ) {
63
+        // TODO don't allow to call with empty string
64 64
 
65
-		return \WMDE\HamcrestHtml\ClassMatcher::withClass( $class );
66
-	}
65
+        return \WMDE\HamcrestHtml\ClassMatcher::withClass( $class );
66
+    }
67 67
 }
68 68
 
69 69
 if ( !function_exists( 'havingTextContents' ) ) {
70
-	/**
71
-	 * @param Matcher|string $text
72
-	 *
73
-	 * @return \WMDE\HamcrestHtml\TextContentsMatcher
74
-	 */
75
-	function havingTextContents( $text ) {
76
-		return \WMDE\HamcrestHtml\TextContentsMatcher::havingTextContents( $text );
77
-	}
70
+    /**
71
+     * @param Matcher|string $text
72
+     *
73
+     * @return \WMDE\HamcrestHtml\TextContentsMatcher
74
+     */
75
+    function havingTextContents( $text ) {
76
+        return \WMDE\HamcrestHtml\TextContentsMatcher::havingTextContents( $text );
77
+    }
78 78
 }
79 79
 
80 80
 if ( !function_exists( 'tagMatchingOutline' ) ) {
81
-	/**
82
-	 * @param string $htmlOutline
83
-	 *
84
-	 * @return \WMDE\HamcrestHtml\ComplexTagMatcher
85
-	 */
86
-	function tagMatchingOutline( $htmlOutline ) {
87
-		return \WMDE\HamcrestHtml\ComplexTagMatcher::tagMatchingOutline( $htmlOutline );
88
-	}
81
+    /**
82
+     * @param string $htmlOutline
83
+     *
84
+     * @return \WMDE\HamcrestHtml\ComplexTagMatcher
85
+     */
86
+    function tagMatchingOutline( $htmlOutline ) {
87
+        return \WMDE\HamcrestHtml\ComplexTagMatcher::tagMatchingOutline( $htmlOutline );
88
+    }
89 89
 }
90 90
 
91 91
 if ( !function_exists( 'containsStringIgnoringWhiteSpace' ) ) {
92
-	/**
93
-	 * @param string $substring
94
-	 *
95
-	 * @return \WMDE\HamcrestHtml\StringContainsIgnoringWhiteSpace
96
-	 */
97
-	function containsStringIgnoringWhiteSpace( $substring ) {
98
-		return \WMDE\HamcrestHtml\StringContainsIgnoringWhiteSpace::containsStringIgnoringWhiteSpace(
99
-			$substring
100
-		);
101
-	}
92
+    /**
93
+     * @param string $substring
94
+     *
95
+     * @return \WMDE\HamcrestHtml\StringContainsIgnoringWhiteSpace
96
+     */
97
+    function containsStringIgnoringWhiteSpace( $substring ) {
98
+        return \WMDE\HamcrestHtml\StringContainsIgnoringWhiteSpace::containsStringIgnoringWhiteSpace(
99
+            $substring
100
+        );
101
+    }
102 102
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -2,99 +2,99 @@
 block discarded – undo
2 2
 
3 3
 use Hamcrest\Matcher;
4 4
 
5
-if ( !function_exists( 'htmlPiece' ) ) {
5
+if (!function_exists('htmlPiece')) {
6 6
 	/**
7 7
 	 * @param Matcher|null $elementMatcher
8 8
 	 *
9 9
 	 * @return \WMDE\HamcrestHtml\HtmlMatcher
10 10
 	 */
11
-	function htmlPiece( Matcher $elementMatcher = null ) {
12
-		return \WMDE\HamcrestHtml\HtmlMatcher::htmlPiece( $elementMatcher );
11
+	function htmlPiece(Matcher $elementMatcher = null) {
12
+		return \WMDE\HamcrestHtml\HtmlMatcher::htmlPiece($elementMatcher);
13 13
 	}
14 14
 }
15 15
 
16
-if ( !function_exists( 'havingRootElement' ) ) {
17
-	function havingRootElement( Matcher $matcher = null ) {
18
-		return \WMDE\HamcrestHtml\RootElementMatcher::havingRootElement( $matcher );
16
+if (!function_exists('havingRootElement')) {
17
+	function havingRootElement(Matcher $matcher = null) {
18
+		return \WMDE\HamcrestHtml\RootElementMatcher::havingRootElement($matcher);
19 19
 	}
20 20
 }
21 21
 
22
-if ( !function_exists( 'havingDirectChild' ) ) {
23
-	function havingDirectChild( Matcher $elementMatcher = null ) {
24
-		return \WMDE\HamcrestHtml\DirectChildElementMatcher::havingDirectChild( $elementMatcher );
22
+if (!function_exists('havingDirectChild')) {
23
+	function havingDirectChild(Matcher $elementMatcher = null) {
24
+		return \WMDE\HamcrestHtml\DirectChildElementMatcher::havingDirectChild($elementMatcher);
25 25
 	}
26 26
 }
27 27
 
28
-if ( !function_exists( 'havingChild' ) ) {
29
-	function havingChild( Matcher $elementMatcher = null ) {
30
-		return \WMDE\HamcrestHtml\ChildElementMatcher::havingChild( $elementMatcher );
28
+if (!function_exists('havingChild')) {
29
+	function havingChild(Matcher $elementMatcher = null) {
30
+		return \WMDE\HamcrestHtml\ChildElementMatcher::havingChild($elementMatcher);
31 31
 	}
32 32
 }
33 33
 
34
-if ( !function_exists( 'withTagName' ) ) {
34
+if (!function_exists('withTagName')) {
35 35
 	/**
36 36
 	 * @param Matcher|string $tagName
37 37
 	 *
38 38
 	 * @return \WMDE\HamcrestHtml\TagNameMatcher
39 39
 	 */
40
-	function withTagName( $tagName ) {
41
-		return \WMDE\HamcrestHtml\TagNameMatcher::withTagName( $tagName );
40
+	function withTagName($tagName) {
41
+		return \WMDE\HamcrestHtml\TagNameMatcher::withTagName($tagName);
42 42
 	}
43 43
 }
44 44
 
45
-if ( !function_exists( 'withAttribute' ) ) {
45
+if (!function_exists('withAttribute')) {
46 46
 	/**
47 47
 	 * @param Matcher|string $attributeName
48 48
 	 *
49 49
 	 * @return \WMDE\HamcrestHtml\AttributeMatcher
50 50
 	 */
51
-	function withAttribute( $attributeName ) {
52
-		return \WMDE\HamcrestHtml\AttributeMatcher::withAttribute( $attributeName );
51
+	function withAttribute($attributeName) {
52
+		return \WMDE\HamcrestHtml\AttributeMatcher::withAttribute($attributeName);
53 53
 	}
54 54
 }
55 55
 
56
-if ( !function_exists( 'withClass' ) ) {
56
+if (!function_exists('withClass')) {
57 57
 	/**
58 58
 	 * @param Matcher|string $class
59 59
 	 *
60 60
 	 * @return \WMDE\HamcrestHtml\ClassMatcher
61 61
 	 */
62
-	function withClass( $class ) {
62
+	function withClass($class) {
63 63
 		// TODO don't allow to call with empty string
64 64
 
65
-		return \WMDE\HamcrestHtml\ClassMatcher::withClass( $class );
65
+		return \WMDE\HamcrestHtml\ClassMatcher::withClass($class);
66 66
 	}
67 67
 }
68 68
 
69
-if ( !function_exists( 'havingTextContents' ) ) {
69
+if (!function_exists('havingTextContents')) {
70 70
 	/**
71 71
 	 * @param Matcher|string $text
72 72
 	 *
73 73
 	 * @return \WMDE\HamcrestHtml\TextContentsMatcher
74 74
 	 */
75
-	function havingTextContents( $text ) {
76
-		return \WMDE\HamcrestHtml\TextContentsMatcher::havingTextContents( $text );
75
+	function havingTextContents($text) {
76
+		return \WMDE\HamcrestHtml\TextContentsMatcher::havingTextContents($text);
77 77
 	}
78 78
 }
79 79
 
80
-if ( !function_exists( 'tagMatchingOutline' ) ) {
80
+if (!function_exists('tagMatchingOutline')) {
81 81
 	/**
82 82
 	 * @param string $htmlOutline
83 83
 	 *
84 84
 	 * @return \WMDE\HamcrestHtml\ComplexTagMatcher
85 85
 	 */
86
-	function tagMatchingOutline( $htmlOutline ) {
87
-		return \WMDE\HamcrestHtml\ComplexTagMatcher::tagMatchingOutline( $htmlOutline );
86
+	function tagMatchingOutline($htmlOutline) {
87
+		return \WMDE\HamcrestHtml\ComplexTagMatcher::tagMatchingOutline($htmlOutline);
88 88
 	}
89 89
 }
90 90
 
91
-if ( !function_exists( 'containsStringIgnoringWhiteSpace' ) ) {
91
+if (!function_exists('containsStringIgnoringWhiteSpace')) {
92 92
 	/**
93 93
 	 * @param string $substring
94 94
 	 *
95 95
 	 * @return \WMDE\HamcrestHtml\StringContainsIgnoringWhiteSpace
96 96
 	 */
97
-	function containsStringIgnoringWhiteSpace( $substring ) {
97
+	function containsStringIgnoringWhiteSpace($substring) {
98 98
 		return \WMDE\HamcrestHtml\StringContainsIgnoringWhiteSpace::containsStringIgnoringWhiteSpace(
99 99
 			$substring
100 100
 		);
Please login to merge, or discard this patch.