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.
Test Failed
Pull Request — master (#12)
by no
03:40
created
src/ChildElementMatcher.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -8,57 +8,57 @@
 block discarded – undo
8 8
 
9 9
 class ChildElementMatcher extends TypeSafeDiagnosingMatcher {
10 10
 
11
-	/**
12
-	 * @var Matcher|null
13
-	 */
14
-	private $matcher;
11
+    /**
12
+     * @var Matcher|null
13
+     */
14
+    private $matcher;
15 15
 
16
-	public static function havingChild( Matcher $elementMatcher = null ) {
17
-		return new static( $elementMatcher );
18
-	}
16
+    public static function havingChild( Matcher $elementMatcher = null ) {
17
+        return new static( $elementMatcher );
18
+    }
19 19
 
20
-	public function __construct( Matcher $matcher = null ) {
21
-		parent::__construct( \DOMNode::class );
22
-		$this->matcher = $matcher;
23
-	}
20
+    public function __construct( Matcher $matcher = null ) {
21
+        parent::__construct( \DOMNode::class );
22
+        $this->matcher = $matcher;
23
+    }
24 24
 
25
-	public function describeTo( Description $description ) {
26
-		$description->appendText( 'having child ' );
27
-		if ( $this->matcher ) {
28
-			$description->appendDescriptionOf( $this->matcher );
29
-		}
30
-	}
25
+    public function describeTo( Description $description ) {
26
+        $description->appendText( 'having child ' );
27
+        if ( $this->matcher ) {
28
+            $description->appendDescriptionOf( $this->matcher );
29
+        }
30
+    }
31 31
 
32
-	/**
33
-	 * @param \DOMDocument|\DOMNode $item
34
-	 * @param Description $mismatchDescription
35
-	 *
36
-	 * @return bool
37
-	 */
38
-	protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) {
39
-		if ( $item instanceof \DOMDocument ) {
40
-			$directChildren = $item->documentElement->childNodes->item( 0 )->childNodes;
41
-		} else {
42
-			$directChildren = $item->childNodes;
43
-		}
32
+    /**
33
+     * @param \DOMDocument|\DOMNode $item
34
+     * @param Description $mismatchDescription
35
+     *
36
+     * @return bool
37
+     */
38
+    protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) {
39
+        if ( $item instanceof \DOMDocument ) {
40
+            $directChildren = $item->documentElement->childNodes->item( 0 )->childNodes;
41
+        } else {
42
+            $directChildren = $item->childNodes;
43
+        }
44 44
 
45
-		if ( $directChildren->length === 0 ) {
46
-			$mismatchDescription->appendText( 'having no children' );
47
-			return false;
48
-		}
45
+        if ( $directChildren->length === 0 ) {
46
+            $mismatchDescription->appendText( 'having no children' );
47
+            return false;
48
+        }
49 49
 
50
-		if ( !$this->matcher ) {
51
-			return $directChildren->length > 0;
52
-		}
50
+        if ( !$this->matcher ) {
51
+            return $directChildren->length > 0;
52
+        }
53 53
 
54
-		foreach ( new XmlNodeRecursiveIterator( $directChildren ) as $child ) {
55
-			if ( $this->matcher->matches( $child ) ) {
56
-				return true;
57
-			}
58
-		}
54
+        foreach ( new XmlNodeRecursiveIterator( $directChildren ) as $child ) {
55
+            if ( $this->matcher->matches( $child ) ) {
56
+                return true;
57
+            }
58
+        }
59 59
 
60
-		$mismatchDescription->appendText( 'having no children ' )->appendDescriptionOf( $this->matcher );
61
-		return false;
62
-	}
60
+        $mismatchDescription->appendText( 'having no children ' )->appendDescriptionOf( $this->matcher );
61
+        return false;
62
+    }
63 63
 
64 64
 }
Please login to merge, or discard this patch.
src/ComplexTagMatcher.php 1 patch
Indentation   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -10,187 +10,187 @@
 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
-	 * @return self
32
-	 */
33
-	public static function tagMatchingOutline( $htmlOutline ) {
34
-		return new self( $htmlOutline );
35
-	}
36
-
37
-	public function __construct( $tagHtmlRepresentation ) {
38
-		parent::__construct();
39
-
40
-		$this->tagHtmlOutline = $tagHtmlRepresentation;
41
-		$this->matcher = $this->createMatcherFromHtml( $tagHtmlRepresentation );
42
-	}
43
-
44
-	public function describeTo( Description $description ) {
45
-		$description->appendText( 'tag matching outline `' )
46
-			->appendText( $this->tagHtmlOutline )
47
-			->appendText( '` ' );
48
-	}
49
-
50
-	/**
51
-	 * @param \DOMElement $item
52
-	 * @param Description $mismatchDescription
53
-	 *
54
-	 * @return bool
55
-	 */
56
-	protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) {
57
-		if ( $this->matcher->matches( $item ) ) {
58
-			return true;
59
-		}
60
-
61
-		$mismatchDescription->appendText( 'was `' )
62
-			->appendText( $this->elementToString( $item ) )
63
-			->appendText( '`' );
64
-		return false;
65
-	}
66
-
67
-	private function createMatcherFromHtml( $htmlOutline ) {
68
-		$document = $this->parseHtml( $htmlOutline );
69
-		$targetTag = $this->getSingleTagFromThe( $document );
70
-
71
-		$this->assertTagDoesNotContainChildren( $targetTag );
72
-
73
-		$attributeMatchers = $this->createAttributeMatchers( $htmlOutline, $targetTag );
74
-		$classMatchers = $this->createClassMatchers( $targetTag );
75
-
76
-		return AllOf::allOf(
77
-			new TagNameMatcher( IsEqual::equalTo( $targetTag->tagName ) ),
78
-			call_user_func_array( [ AllOf::class, 'allOf' ], $attributeMatchers ),
79
-			call_user_func_array( [ AllOf::class, 'allOf' ], $classMatchers )
80
-		);
81
-	}
82
-
83
-	private function isUnknownTagError( \LibXMLError $error ) {
84
-		return $error->code === self::XML_UNKNOWN_TAG_ERROR_CODE;
85
-	}
86
-
87
-	private function isBooleanAttribute( $inputHtml, $attributeName ) {
88
-		$quotedName = preg_quote( $attributeName, '/' );
89
-
90
-		$attributeHasValueAssigned = preg_match( "/\b{$quotedName}\s*=/ui", $inputHtml );
91
-		return !$attributeHasValueAssigned;
92
-	}
93
-
94
-	/**
95
-	 * @param $html
96
-	 *
97
-	 * @return \DOMDocument
98
-	 * @throws \InvalidArgumentException
99
-	 */
100
-	private function parseHtml( $html ) {
101
-		$internalErrors = libxml_use_internal_errors( true );
102
-		$document = new \DOMDocument();
103
-
104
-		if ( !@$document->loadHTML( $html ) ) {
105
-			throw new \InvalidArgumentException( "There was some parsing error of `$html`" );
106
-		}
107
-
108
-		$errors = libxml_get_errors();
109
-		libxml_clear_errors();
110
-		libxml_use_internal_errors( $internalErrors );
111
-
112
-		/** @var \LibXMLError $error */
113
-		foreach ( $errors as $error ) {
114
-			if ( $this->isUnknownTagError( $error ) ) {
115
-				continue;
116
-			}
117
-
118
-			throw new \InvalidArgumentException(
119
-				'There was parsing error: ' . trim( $error->message ) . ' on line ' . $error->line
120
-			);
121
-		}
122
-
123
-		return $document;
124
-	}
125
-
126
-	/**
127
-	 * @param \DOMDocument $document
128
-	 *
129
-	 * @return \DOMElement
130
-	 * @throws \InvalidArgumentException
131
-	 */
132
-	private function getSingleTagFromThe( \DOMDocument $document ) {
133
-		$directChildren = $document->documentElement->childNodes->item( 0 )->childNodes;
134
-
135
-		if ( $directChildren->length !== 1 ) {
136
-			throw new InvalidArgumentException(
137
-				'Expected exactly 1 tag description, got ' . $directChildren->length
138
-			);
139
-		}
140
-
141
-		return $directChildren[0];
142
-	}
143
-
144
-	private function assertTagDoesNotContainChildren( \DOMElement $targetTag ) {
145
-		if ( $targetTag->childNodes->length > 0 ) {
146
-			throw new InvalidArgumentException( 'Nested elements are not allowed' );
147
-		}
148
-	}
149
-
150
-	/**
151
-	 * @param string $inputHtml
152
-	 * @param $targetTag
153
-	 * @return AttributeMatcher[]
154
-	 */
155
-	private function createAttributeMatchers( $inputHtml, \DOMElement $targetTag ) {
156
-		$attributeMatchers = [];
157
-		/** @var \DOMAttr $attribute */
158
-		foreach ( $targetTag->attributes as $attribute ) {
159
-			if ( $attribute->name === 'class' ) {
160
-				continue;
161
-			}
162
-
163
-			$attributeMatcher = new AttributeMatcher( IsEqual::equalTo( $attribute->name ) );
164
-			if ( !$this->isBooleanAttribute( $inputHtml, $attribute->name ) ) {
165
-				$attributeMatcher = $attributeMatcher->havingValue( IsEqual::equalTo( $attribute->value ) );
166
-			}
167
-
168
-			$attributeMatchers[] = $attributeMatcher;
169
-		}
170
-		return $attributeMatchers;
171
-	}
172
-
173
-	/**
174
-	 * @param \DOMElement $targetTag
175
-	 * @return ClassMatcher[]
176
-	 */
177
-	private function createClassMatchers( $targetTag ) {
178
-		$classMatchers = [];
179
-		$classValue = $targetTag->getAttribute( 'class' );
180
-		foreach ( explode( ' ', $classValue ) as $expectedClass ) {
181
-			if ( $expectedClass === '' ) {
182
-				continue;
183
-			}
184
-			$classMatchers[] = new ClassMatcher( IsEqual::equalTo( $expectedClass ) );
185
-		}
186
-		return $classMatchers;
187
-	}
188
-
189
-	private function elementToString( \DOMElement $element ) {
190
-		$newDocument = new \DOMDocument();
191
-		$cloned = $element->cloneNode( true );
192
-		$newDocument->appendChild( $newDocument->importNode( $cloned, true ) );
193
-		return trim( $newDocument->saveHTML() );
194
-	}
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
+     * @return self
32
+     */
33
+    public static function tagMatchingOutline( $htmlOutline ) {
34
+        return new self( $htmlOutline );
35
+    }
36
+
37
+    public function __construct( $tagHtmlRepresentation ) {
38
+        parent::__construct();
39
+
40
+        $this->tagHtmlOutline = $tagHtmlRepresentation;
41
+        $this->matcher = $this->createMatcherFromHtml( $tagHtmlRepresentation );
42
+    }
43
+
44
+    public function describeTo( Description $description ) {
45
+        $description->appendText( 'tag matching outline `' )
46
+            ->appendText( $this->tagHtmlOutline )
47
+            ->appendText( '` ' );
48
+    }
49
+
50
+    /**
51
+     * @param \DOMElement $item
52
+     * @param Description $mismatchDescription
53
+     *
54
+     * @return bool
55
+     */
56
+    protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) {
57
+        if ( $this->matcher->matches( $item ) ) {
58
+            return true;
59
+        }
60
+
61
+        $mismatchDescription->appendText( 'was `' )
62
+            ->appendText( $this->elementToString( $item ) )
63
+            ->appendText( '`' );
64
+        return false;
65
+    }
66
+
67
+    private function createMatcherFromHtml( $htmlOutline ) {
68
+        $document = $this->parseHtml( $htmlOutline );
69
+        $targetTag = $this->getSingleTagFromThe( $document );
70
+
71
+        $this->assertTagDoesNotContainChildren( $targetTag );
72
+
73
+        $attributeMatchers = $this->createAttributeMatchers( $htmlOutline, $targetTag );
74
+        $classMatchers = $this->createClassMatchers( $targetTag );
75
+
76
+        return AllOf::allOf(
77
+            new TagNameMatcher( IsEqual::equalTo( $targetTag->tagName ) ),
78
+            call_user_func_array( [ AllOf::class, 'allOf' ], $attributeMatchers ),
79
+            call_user_func_array( [ AllOf::class, 'allOf' ], $classMatchers )
80
+        );
81
+    }
82
+
83
+    private function isUnknownTagError( \LibXMLError $error ) {
84
+        return $error->code === self::XML_UNKNOWN_TAG_ERROR_CODE;
85
+    }
86
+
87
+    private function isBooleanAttribute( $inputHtml, $attributeName ) {
88
+        $quotedName = preg_quote( $attributeName, '/' );
89
+
90
+        $attributeHasValueAssigned = preg_match( "/\b{$quotedName}\s*=/ui", $inputHtml );
91
+        return !$attributeHasValueAssigned;
92
+    }
93
+
94
+    /**
95
+     * @param $html
96
+     *
97
+     * @return \DOMDocument
98
+     * @throws \InvalidArgumentException
99
+     */
100
+    private function parseHtml( $html ) {
101
+        $internalErrors = libxml_use_internal_errors( true );
102
+        $document = new \DOMDocument();
103
+
104
+        if ( !@$document->loadHTML( $html ) ) {
105
+            throw new \InvalidArgumentException( "There was some parsing error of `$html`" );
106
+        }
107
+
108
+        $errors = libxml_get_errors();
109
+        libxml_clear_errors();
110
+        libxml_use_internal_errors( $internalErrors );
111
+
112
+        /** @var \LibXMLError $error */
113
+        foreach ( $errors as $error ) {
114
+            if ( $this->isUnknownTagError( $error ) ) {
115
+                continue;
116
+            }
117
+
118
+            throw new \InvalidArgumentException(
119
+                'There was parsing error: ' . trim( $error->message ) . ' on line ' . $error->line
120
+            );
121
+        }
122
+
123
+        return $document;
124
+    }
125
+
126
+    /**
127
+     * @param \DOMDocument $document
128
+     *
129
+     * @return \DOMElement
130
+     * @throws \InvalidArgumentException
131
+     */
132
+    private function getSingleTagFromThe( \DOMDocument $document ) {
133
+        $directChildren = $document->documentElement->childNodes->item( 0 )->childNodes;
134
+
135
+        if ( $directChildren->length !== 1 ) {
136
+            throw new InvalidArgumentException(
137
+                'Expected exactly 1 tag description, got ' . $directChildren->length
138
+            );
139
+        }
140
+
141
+        return $directChildren[0];
142
+    }
143
+
144
+    private function assertTagDoesNotContainChildren( \DOMElement $targetTag ) {
145
+        if ( $targetTag->childNodes->length > 0 ) {
146
+            throw new InvalidArgumentException( 'Nested elements are not allowed' );
147
+        }
148
+    }
149
+
150
+    /**
151
+     * @param string $inputHtml
152
+     * @param $targetTag
153
+     * @return AttributeMatcher[]
154
+     */
155
+    private function createAttributeMatchers( $inputHtml, \DOMElement $targetTag ) {
156
+        $attributeMatchers = [];
157
+        /** @var \DOMAttr $attribute */
158
+        foreach ( $targetTag->attributes as $attribute ) {
159
+            if ( $attribute->name === 'class' ) {
160
+                continue;
161
+            }
162
+
163
+            $attributeMatcher = new AttributeMatcher( IsEqual::equalTo( $attribute->name ) );
164
+            if ( !$this->isBooleanAttribute( $inputHtml, $attribute->name ) ) {
165
+                $attributeMatcher = $attributeMatcher->havingValue( IsEqual::equalTo( $attribute->value ) );
166
+            }
167
+
168
+            $attributeMatchers[] = $attributeMatcher;
169
+        }
170
+        return $attributeMatchers;
171
+    }
172
+
173
+    /**
174
+     * @param \DOMElement $targetTag
175
+     * @return ClassMatcher[]
176
+     */
177
+    private function createClassMatchers( $targetTag ) {
178
+        $classMatchers = [];
179
+        $classValue = $targetTag->getAttribute( 'class' );
180
+        foreach ( explode( ' ', $classValue ) as $expectedClass ) {
181
+            if ( $expectedClass === '' ) {
182
+                continue;
183
+            }
184
+            $classMatchers[] = new ClassMatcher( IsEqual::equalTo( $expectedClass ) );
185
+        }
186
+        return $classMatchers;
187
+    }
188
+
189
+    private function elementToString( \DOMElement $element ) {
190
+        $newDocument = new \DOMDocument();
191
+        $cloned = $element->cloneNode( true );
192
+        $newDocument->appendChild( $newDocument->importNode( $cloned, true ) );
193
+        return trim( $newDocument->saveHTML() );
194
+    }
195 195
 
196 196
 }
Please login to merge, or discard this patch.