@@ -7,7 +7,7 @@ |
||
| 7 | 7 | abstract class TagMatcher extends TypeSafeDiagnosingMatcher { |
| 8 | 8 | |
| 9 | 9 | public function __construct() { |
| 10 | - parent::__construct( self::TYPE_OBJECT, \DOMElement::class ); |
|
| 10 | + parent::__construct(self::TYPE_OBJECT, \DOMElement::class); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | } |
@@ -24,66 +24,66 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @return HtmlMatcher |
| 26 | 26 | */ |
| 27 | - public static function htmlPiece( Matcher $elementMatcher = null ) { |
|
| 28 | - return new static( $elementMatcher ); |
|
| 27 | + public static function htmlPiece(Matcher $elementMatcher = null) { |
|
| 28 | + return new static($elementMatcher); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - private function __construct( Matcher $elementMatcher = null ) { |
|
| 31 | + private function __construct(Matcher $elementMatcher = null) { |
|
| 32 | 32 | $this->elementMatcher = $elementMatcher; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - public function describeTo( Description $description ) { |
|
| 36 | - $description->appendText( 'valid html piece ' ); |
|
| 37 | - if ( $this->elementMatcher ) { |
|
| 38 | - $description->appendDescriptionOf( $this->elementMatcher ); |
|
| 35 | + public function describeTo(Description $description) { |
|
| 36 | + $description->appendText('valid html piece '); |
|
| 37 | + if ($this->elementMatcher) { |
|
| 38 | + $description->appendDescriptionOf($this->elementMatcher); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - protected function matchesWithDiagnosticDescription( $html, Description $mismatchDescription ) { |
|
| 43 | - $internalErrors = libxml_use_internal_errors( true ); |
|
| 42 | + protected function matchesWithDiagnosticDescription($html, Description $mismatchDescription) { |
|
| 43 | + $internalErrors = libxml_use_internal_errors(true); |
|
| 44 | 44 | $document = new \DOMDocument(); |
| 45 | 45 | |
| 46 | - $html = $this->escapeScriptTagContents( $html ); |
|
| 46 | + $html = $this->escapeScriptTagContents($html); |
|
| 47 | 47 | |
| 48 | - if ( !@$document->loadHTML( mb_convert_encoding( $html, 'HTML-ENTITIES', 'UTF-8' ) ) ) { |
|
| 49 | - $mismatchDescription->appendText( 'there was some parsing error' ); |
|
| 48 | + if (!@$document->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'))) { |
|
| 49 | + $mismatchDescription->appendText('there was some parsing error'); |
|
| 50 | 50 | return false; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | $errors = libxml_get_errors(); |
| 54 | 54 | libxml_clear_errors(); |
| 55 | - libxml_use_internal_errors( $internalErrors ); |
|
| 55 | + libxml_use_internal_errors($internalErrors); |
|
| 56 | 56 | |
| 57 | 57 | $result = true; |
| 58 | 58 | /** @var \LibXMLError $error */ |
| 59 | - foreach ( $errors as $error ) { |
|
| 60 | - if ( $this->isUnknownTagError( $error ) ) { |
|
| 59 | + foreach ($errors as $error) { |
|
| 60 | + if ($this->isUnknownTagError($error)) { |
|
| 61 | 61 | continue; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - $mismatchDescription->appendText( 'there was parsing error: ' ) |
|
| 65 | - ->appendText( trim( $error->message ) ) |
|
| 66 | - ->appendText( ' on line ' ) |
|
| 67 | - ->appendText( $error->line ); |
|
| 64 | + $mismatchDescription->appendText('there was parsing error: ') |
|
| 65 | + ->appendText(trim($error->message)) |
|
| 66 | + ->appendText(' on line ') |
|
| 67 | + ->appendText($error->line); |
|
| 68 | 68 | $result = false; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - if ( $result === false ) { |
|
| 71 | + if ($result === false) { |
|
| 72 | 72 | return $result; |
| 73 | 73 | } |
| 74 | - $mismatchDescription->appendText( 'valid html piece ' ); |
|
| 74 | + $mismatchDescription->appendText('valid html piece '); |
|
| 75 | 75 | |
| 76 | - if ( $this->elementMatcher ) { |
|
| 77 | - $result = $this->elementMatcher->matches( $document ); |
|
| 78 | - $this->elementMatcher->describeMismatch( $document, $mismatchDescription ); |
|
| 76 | + if ($this->elementMatcher) { |
|
| 77 | + $result = $this->elementMatcher->matches($document); |
|
| 78 | + $this->elementMatcher->describeMismatch($document, $mismatchDescription); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - $mismatchDescription->appendText( "\nActual html:\n" )->appendText( $html ); |
|
| 81 | + $mismatchDescription->appendText("\nActual html:\n")->appendText($html); |
|
| 82 | 82 | |
| 83 | 83 | return $result; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - private function isUnknownTagError( \LibXMLError $error ) { |
|
| 86 | + private function isUnknownTagError(\LibXMLError $error) { |
|
| 87 | 87 | return $error->code === self::XML_UNKNOWN_TAG_ERROR_CODE; |
| 88 | 88 | } |
| 89 | 89 | |
@@ -92,10 +92,10 @@ discard block |
||
| 92 | 92 | * |
| 93 | 93 | * @return string HTML |
| 94 | 94 | */ |
| 95 | - private function escapeScriptTagContents( $html ) { |
|
| 96 | - return preg_replace_callback( '#(<script.*>)(.*)(</script>)#isU', function ( $matches ) { |
|
| 97 | - return $matches[1] . str_replace( '</', '<\/', $matches[2] ) . $matches[3]; |
|
| 98 | - }, $html ); |
|
| 95 | + private function escapeScriptTagContents($html) { |
|
| 96 | + return preg_replace_callback('#(<script.*>)(.*)(</script>)#isU', function($matches) { |
|
| 97 | + return $matches[1] . str_replace('</', '<\/', $matches[2]) . $matches[3]; |
|
| 98 | + }, $html); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | } |