@@ -6,8 +6,8 @@ |
||
| 6 | 6 | |
| 7 | 7 | abstract class TagMatcher extends TypeSafeDiagnosingMatcher { |
| 8 | 8 | |
| 9 | - public function __construct() { |
|
| 10 | - parent::__construct( self::TYPE_OBJECT, \DOMElement::class ); |
|
| 11 | - } |
|
| 9 | + public function __construct() { |
|
| 10 | + parent::__construct( self::TYPE_OBJECT, \DOMElement::class ); |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | 13 | } |
@@ -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 | } |
@@ -4,27 +4,27 @@ |
||
| 4 | 4 | |
| 5 | 5 | class XmlNodeRecursiveIterator extends \ArrayIterator { |
| 6 | 6 | |
| 7 | - public function __construct( \DOMNodeList $nodeList ) { |
|
| 8 | - $queue = $this->addElementsToQueue( [], $nodeList ); |
|
| 9 | - parent::__construct( $queue ); |
|
| 10 | - } |
|
| 7 | + public function __construct( \DOMNodeList $nodeList ) { |
|
| 8 | + $queue = $this->addElementsToQueue( [], $nodeList ); |
|
| 9 | + parent::__construct( $queue ); |
|
| 10 | + } |
|
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @param \DOMNode[] $queue |
|
| 14 | - * @param \DOMNodeList $nodeList |
|
| 15 | - * |
|
| 16 | - * @return \DOMNode[] New queue |
|
| 17 | - */ |
|
| 18 | - private function addElementsToQueue( array $queue, \DOMNodeList $nodeList ) { |
|
| 19 | - /** @var \DOMNode $node */ |
|
| 20 | - foreach ( $nodeList as $node ) { |
|
| 21 | - $queue[] = $node; |
|
| 22 | - if ( $node->childNodes !== null ) { |
|
| 23 | - $queue = $this->addElementsToQueue( $queue, $node->childNodes ); |
|
| 24 | - } |
|
| 25 | - } |
|
| 12 | + /** |
|
| 13 | + * @param \DOMNode[] $queue |
|
| 14 | + * @param \DOMNodeList $nodeList |
|
| 15 | + * |
|
| 16 | + * @return \DOMNode[] New queue |
|
| 17 | + */ |
|
| 18 | + private function addElementsToQueue( array $queue, \DOMNodeList $nodeList ) { |
|
| 19 | + /** @var \DOMNode $node */ |
|
| 20 | + foreach ( $nodeList as $node ) { |
|
| 21 | + $queue[] = $node; |
|
| 22 | + if ( $node->childNodes !== null ) { |
|
| 23 | + $queue = $this->addElementsToQueue( $queue, $node->childNodes ); |
|
| 24 | + } |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - return $queue; |
|
| 28 | - } |
|
| 27 | + return $queue; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | 30 | } |
@@ -4,9 +4,9 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | class XmlNodeRecursiveIterator extends \ArrayIterator { |
| 6 | 6 | |
| 7 | - public function __construct( \DOMNodeList $nodeList ) { |
|
| 8 | - $queue = $this->addElementsToQueue( [], $nodeList ); |
|
| 9 | - parent::__construct( $queue ); |
|
| 7 | + public function __construct(\DOMNodeList $nodeList) { |
|
| 8 | + $queue = $this->addElementsToQueue([], $nodeList); |
|
| 9 | + parent::__construct($queue); |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | /** |
@@ -15,12 +15,12 @@ discard block |
||
| 15 | 15 | * |
| 16 | 16 | * @return \DOMNode[] New queue |
| 17 | 17 | */ |
| 18 | - private function addElementsToQueue( array $queue, \DOMNodeList $nodeList ) { |
|
| 18 | + private function addElementsToQueue(array $queue, \DOMNodeList $nodeList) { |
|
| 19 | 19 | /** @var \DOMNode $node */ |
| 20 | - foreach ( $nodeList as $node ) { |
|
| 20 | + foreach ($nodeList as $node) { |
|
| 21 | 21 | $queue[] = $node; |
| 22 | - if ( $node->childNodes !== null ) { |
|
| 23 | - $queue = $this->addElementsToQueue( $queue, $node->childNodes ); |
|
| 22 | + if ($node->childNodes !== null) { |
|
| 23 | + $queue = $this->addElementsToQueue($queue, $node->childNodes); |
|
| 24 | 24 | } |
| 25 | 25 | } |
| 26 | 26 | |
@@ -3,87 +3,87 @@ |
||
| 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 | } |
@@ -2,88 +2,88 @@ |
||
| 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 | } |
@@ -8,60 +8,60 @@ |
||
| 8 | 8 | |
| 9 | 9 | class RootElementMatcher extends TypeSafeDiagnosingMatcher { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * @var Matcher |
|
| 13 | - */ |
|
| 14 | - private $tagMatcher; |
|
| 11 | + /** |
|
| 12 | + * @var Matcher |
|
| 13 | + */ |
|
| 14 | + private $tagMatcher; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @param Matcher|null $tagMatcher |
|
| 18 | - * |
|
| 19 | - * @return static |
|
| 20 | - */ |
|
| 21 | - public static function havingRootElement( Matcher $tagMatcher = null ) { |
|
| 22 | - return new static( $tagMatcher ); |
|
| 23 | - } |
|
| 16 | + /** |
|
| 17 | + * @param Matcher|null $tagMatcher |
|
| 18 | + * |
|
| 19 | + * @return static |
|
| 20 | + */ |
|
| 21 | + public static function havingRootElement( Matcher $tagMatcher = null ) { |
|
| 22 | + return new static( $tagMatcher ); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - public function __construct( Matcher $tagMatcher = null ) { |
|
| 26 | - parent::__construct( self::TYPE_OBJECT, \DOMDocument::class ); |
|
| 27 | - $this->tagMatcher = $tagMatcher; |
|
| 28 | - } |
|
| 25 | + public function __construct( Matcher $tagMatcher = null ) { |
|
| 26 | + parent::__construct( self::TYPE_OBJECT, \DOMDocument::class ); |
|
| 27 | + $this->tagMatcher = $tagMatcher; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - public function describeTo( Description $description ) { |
|
| 31 | - $description->appendText( 'having root element ' ); |
|
| 32 | - if ( $this->tagMatcher ) { |
|
| 33 | - $description->appendDescriptionOf( $this->tagMatcher ); |
|
| 34 | - } |
|
| 35 | - } |
|
| 30 | + public function describeTo( Description $description ) { |
|
| 31 | + $description->appendText( 'having root element ' ); |
|
| 32 | + if ( $this->tagMatcher ) { |
|
| 33 | + $description->appendDescriptionOf( $this->tagMatcher ); |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param \DOMDocument $item |
|
| 39 | - * @param Description $mismatchDescription |
|
| 40 | - * |
|
| 41 | - * @return bool |
|
| 42 | - */ |
|
| 43 | - protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) { |
|
| 44 | - $DOMNodeList = $item->documentElement->childNodes->item( 0 )->childNodes; |
|
| 45 | - if ( $DOMNodeList->length > 1 ) { |
|
| 46 | - // TODO Test this description |
|
| 47 | - $mismatchDescription->appendText( 'having ' . $DOMNodeList->length . ' root elements ' ); |
|
| 48 | - return false; |
|
| 49 | - } |
|
| 37 | + /** |
|
| 38 | + * @param \DOMDocument $item |
|
| 39 | + * @param Description $mismatchDescription |
|
| 40 | + * |
|
| 41 | + * @return bool |
|
| 42 | + */ |
|
| 43 | + protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) { |
|
| 44 | + $DOMNodeList = $item->documentElement->childNodes->item( 0 )->childNodes; |
|
| 45 | + if ( $DOMNodeList->length > 1 ) { |
|
| 46 | + // TODO Test this description |
|
| 47 | + $mismatchDescription->appendText( 'having ' . $DOMNodeList->length . ' root elements ' ); |
|
| 48 | + return false; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - $target = $DOMNodeList->item( 0 ); |
|
| 52 | - if ( !$target ) { |
|
| 53 | - // TODO Reproduce? |
|
| 54 | - $mismatchDescription->appendText( 'having no root elements ' ); |
|
| 55 | - return false; |
|
| 56 | - } |
|
| 51 | + $target = $DOMNodeList->item( 0 ); |
|
| 52 | + if ( !$target ) { |
|
| 53 | + // TODO Reproduce? |
|
| 54 | + $mismatchDescription->appendText( 'having no root elements ' ); |
|
| 55 | + return false; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - if ( $this->tagMatcher ) { |
|
| 59 | - $mismatchDescription->appendText( 'root element ' ); |
|
| 60 | - $this->tagMatcher->describeMismatch( $target, $mismatchDescription ); |
|
| 61 | - return $this->tagMatcher->matches( $target ); |
|
| 62 | - } |
|
| 58 | + if ( $this->tagMatcher ) { |
|
| 59 | + $mismatchDescription->appendText( 'root element ' ); |
|
| 60 | + $this->tagMatcher->describeMismatch( $target, $mismatchDescription ); |
|
| 61 | + return $this->tagMatcher->matches( $target ); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - return true; |
|
| 65 | - } |
|
| 64 | + return true; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | 67 | } |
@@ -18,19 +18,19 @@ discard block |
||
| 18 | 18 | * |
| 19 | 19 | * @return static |
| 20 | 20 | */ |
| 21 | - public static function havingRootElement( Matcher $tagMatcher = null ) { |
|
| 22 | - return new static( $tagMatcher ); |
|
| 21 | + public static function havingRootElement(Matcher $tagMatcher = null) { |
|
| 22 | + return new static($tagMatcher); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - public function __construct( Matcher $tagMatcher = null ) { |
|
| 26 | - parent::__construct( self::TYPE_OBJECT, \DOMDocument::class ); |
|
| 25 | + public function __construct(Matcher $tagMatcher = null) { |
|
| 26 | + parent::__construct(self::TYPE_OBJECT, \DOMDocument::class); |
|
| 27 | 27 | $this->tagMatcher = $tagMatcher; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - public function describeTo( Description $description ) { |
|
| 31 | - $description->appendText( 'having root element ' ); |
|
| 32 | - if ( $this->tagMatcher ) { |
|
| 33 | - $description->appendDescriptionOf( $this->tagMatcher ); |
|
| 30 | + public function describeTo(Description $description) { |
|
| 31 | + $description->appendText('having root element '); |
|
| 32 | + if ($this->tagMatcher) { |
|
| 33 | + $description->appendDescriptionOf($this->tagMatcher); |
|
| 34 | 34 | } |
| 35 | 35 | } |
| 36 | 36 | |
@@ -40,25 +40,25 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @return bool |
| 42 | 42 | */ |
| 43 | - protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) { |
|
| 44 | - $DOMNodeList = $item->documentElement->childNodes->item( 0 )->childNodes; |
|
| 45 | - if ( $DOMNodeList->length > 1 ) { |
|
| 43 | + protected function matchesSafelyWithDiagnosticDescription($item, Description $mismatchDescription) { |
|
| 44 | + $DOMNodeList = $item->documentElement->childNodes->item(0)->childNodes; |
|
| 45 | + if ($DOMNodeList->length > 1) { |
|
| 46 | 46 | // TODO Test this description |
| 47 | - $mismatchDescription->appendText( 'having ' . $DOMNodeList->length . ' root elements ' ); |
|
| 47 | + $mismatchDescription->appendText('having ' . $DOMNodeList->length . ' root elements '); |
|
| 48 | 48 | return false; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - $target = $DOMNodeList->item( 0 ); |
|
| 52 | - if ( !$target ) { |
|
| 51 | + $target = $DOMNodeList->item(0); |
|
| 52 | + if (!$target) { |
|
| 53 | 53 | // TODO Reproduce? |
| 54 | - $mismatchDescription->appendText( 'having no root elements ' ); |
|
| 54 | + $mismatchDescription->appendText('having no root elements '); |
|
| 55 | 55 | return false; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - if ( $this->tagMatcher ) { |
|
| 59 | - $mismatchDescription->appendText( 'root element ' ); |
|
| 60 | - $this->tagMatcher->describeMismatch( $target, $mismatchDescription ); |
|
| 61 | - return $this->tagMatcher->matches( $target ); |
|
| 58 | + if ($this->tagMatcher) { |
|
| 59 | + $mismatchDescription->appendText('root element '); |
|
| 60 | + $this->tagMatcher->describeMismatch($target, $mismatchDescription); |
|
| 61 | + return $this->tagMatcher->matches($target); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | return true; |
@@ -8,61 +8,61 @@ |
||
| 8 | 8 | |
| 9 | 9 | class DirectChildElementMatcher extends TypeSafeDiagnosingMatcher { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * @var Matcher |
|
| 13 | - */ |
|
| 14 | - private $matcher; |
|
| 15 | - |
|
| 16 | - public static function havingDirectChild( Matcher $elementMatcher = null ) { |
|
| 17 | - return new static( $elementMatcher ); |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - public function __construct( Matcher $matcher = null ) { |
|
| 21 | - parent::__construct( \DOMNode::class ); |
|
| 22 | - $this->matcher = $matcher; |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - public function describeTo( Description $description ) { |
|
| 26 | - $description->appendText( 'having direct child ' ); |
|
| 27 | - if ( $this->matcher ) { |
|
| 28 | - $description->appendDescriptionOf( $this->matcher ); |
|
| 29 | - } |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @param \DOMDocument|\DOMNode $item |
|
| 34 | - * @param Description $mismatchDescription |
|
| 35 | - * |
|
| 36 | - * @return bool |
|
| 37 | - */ |
|
| 38 | - protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) { |
|
| 39 | - if ( $item instanceof \DOMDocument ) { |
|
| 40 | - $item = $item->documentElement->childNodes->item( 0 ); |
|
| 41 | - } |
|
| 42 | - $directChildren = $item->childNodes; |
|
| 43 | - |
|
| 44 | - if ( $directChildren->length === 0 ) { |
|
| 45 | - $mismatchDescription->appendText( 'with no direct children' ); |
|
| 46 | - return false; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - $childWord = $directChildren->length === 1 ? 'child' : 'children'; |
|
| 50 | - |
|
| 51 | - $mismatchDescription->appendText( "with direct {$childWord} " ); |
|
| 52 | - |
|
| 53 | - if ( !$this->matcher ) { |
|
| 54 | - return $directChildren->length !== 0; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - foreach ( $directChildren as $child ) { |
|
| 58 | - if ( $this->matcher->matches( $child ) ) { |
|
| 59 | - return true; |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - $this->matcher->describeMismatch( $child, $mismatchDescription ); |
|
| 64 | - |
|
| 65 | - return false; |
|
| 66 | - } |
|
| 11 | + /** |
|
| 12 | + * @var Matcher |
|
| 13 | + */ |
|
| 14 | + private $matcher; |
|
| 15 | + |
|
| 16 | + public static function havingDirectChild( Matcher $elementMatcher = null ) { |
|
| 17 | + return new static( $elementMatcher ); |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + public function __construct( Matcher $matcher = null ) { |
|
| 21 | + parent::__construct( \DOMNode::class ); |
|
| 22 | + $this->matcher = $matcher; |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + public function describeTo( Description $description ) { |
|
| 26 | + $description->appendText( 'having direct child ' ); |
|
| 27 | + if ( $this->matcher ) { |
|
| 28 | + $description->appendDescriptionOf( $this->matcher ); |
|
| 29 | + } |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @param \DOMDocument|\DOMNode $item |
|
| 34 | + * @param Description $mismatchDescription |
|
| 35 | + * |
|
| 36 | + * @return bool |
|
| 37 | + */ |
|
| 38 | + protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) { |
|
| 39 | + if ( $item instanceof \DOMDocument ) { |
|
| 40 | + $item = $item->documentElement->childNodes->item( 0 ); |
|
| 41 | + } |
|
| 42 | + $directChildren = $item->childNodes; |
|
| 43 | + |
|
| 44 | + if ( $directChildren->length === 0 ) { |
|
| 45 | + $mismatchDescription->appendText( 'with no direct children' ); |
|
| 46 | + return false; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + $childWord = $directChildren->length === 1 ? 'child' : 'children'; |
|
| 50 | + |
|
| 51 | + $mismatchDescription->appendText( "with direct {$childWord} " ); |
|
| 52 | + |
|
| 53 | + if ( !$this->matcher ) { |
|
| 54 | + return $directChildren->length !== 0; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + foreach ( $directChildren as $child ) { |
|
| 58 | + if ( $this->matcher->matches( $child ) ) { |
|
| 59 | + return true; |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + $this->matcher->describeMismatch( $child, $mismatchDescription ); |
|
| 64 | + |
|
| 65 | + return false; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | } |
@@ -13,19 +13,19 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | private $matcher; |
| 15 | 15 | |
| 16 | - public static function havingDirectChild( Matcher $elementMatcher = null ) { |
|
| 17 | - return new static( $elementMatcher ); |
|
| 16 | + public static function havingDirectChild(Matcher $elementMatcher = null) { |
|
| 17 | + return new static($elementMatcher); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - public function __construct( Matcher $matcher = null ) { |
|
| 21 | - parent::__construct( \DOMNode::class ); |
|
| 20 | + public function __construct(Matcher $matcher = null) { |
|
| 21 | + parent::__construct(\DOMNode::class); |
|
| 22 | 22 | $this->matcher = $matcher; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - public function describeTo( Description $description ) { |
|
| 26 | - $description->appendText( 'having direct child ' ); |
|
| 27 | - if ( $this->matcher ) { |
|
| 28 | - $description->appendDescriptionOf( $this->matcher ); |
|
| 25 | + public function describeTo(Description $description) { |
|
| 26 | + $description->appendText('having direct child '); |
|
| 27 | + if ($this->matcher) { |
|
| 28 | + $description->appendDescriptionOf($this->matcher); |
|
| 29 | 29 | } |
| 30 | 30 | } |
| 31 | 31 | |
@@ -35,32 +35,32 @@ discard block |
||
| 35 | 35 | * |
| 36 | 36 | * @return bool |
| 37 | 37 | */ |
| 38 | - protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) { |
|
| 39 | - if ( $item instanceof \DOMDocument ) { |
|
| 40 | - $item = $item->documentElement->childNodes->item( 0 ); |
|
| 38 | + protected function matchesSafelyWithDiagnosticDescription($item, Description $mismatchDescription) { |
|
| 39 | + if ($item instanceof \DOMDocument) { |
|
| 40 | + $item = $item->documentElement->childNodes->item(0); |
|
| 41 | 41 | } |
| 42 | 42 | $directChildren = $item->childNodes; |
| 43 | 43 | |
| 44 | - if ( $directChildren->length === 0 ) { |
|
| 45 | - $mismatchDescription->appendText( 'with no direct children' ); |
|
| 44 | + if ($directChildren->length === 0) { |
|
| 45 | + $mismatchDescription->appendText('with no direct children'); |
|
| 46 | 46 | return false; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | $childWord = $directChildren->length === 1 ? 'child' : 'children'; |
| 50 | 50 | |
| 51 | - $mismatchDescription->appendText( "with direct {$childWord} " ); |
|
| 51 | + $mismatchDescription->appendText("with direct {$childWord} "); |
|
| 52 | 52 | |
| 53 | - if ( !$this->matcher ) { |
|
| 53 | + if (!$this->matcher) { |
|
| 54 | 54 | return $directChildren->length !== 0; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - foreach ( $directChildren as $child ) { |
|
| 58 | - if ( $this->matcher->matches( $child ) ) { |
|
| 57 | + foreach ($directChildren as $child) { |
|
| 58 | + if ($this->matcher->matches($child)) { |
|
| 59 | 59 | return true; |
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - $this->matcher->describeMismatch( $child, $mismatchDescription ); |
|
| 63 | + $this->matcher->describeMismatch($child, $mismatchDescription); |
|
| 64 | 64 | |
| 65 | 65 | return false; |
| 66 | 66 | } |
@@ -14,7 +14,7 @@ |
||
| 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 | */ |
@@ -8,75 +8,75 @@ |
||
| 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 | } |
@@ -18,25 +18,25 @@ discard block |
||
| 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 |
||
| 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 | |
@@ -7,114 +7,114 @@ |
||
| 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 | } |
@@ -22,14 +22,14 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -7,49 +7,49 @@ |
||
| 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 | } |
@@ -17,24 +17,24 @@ discard block |
||
| 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 |
||
| 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 | } |
@@ -8,106 +8,106 @@ |
||
| 8 | 8 | |
| 9 | 9 | class HtmlMatcher extends DiagnosingMatcher { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * @link http://www.xmlsoft.org/html/libxml-xmlerror.html#xmlParserErrors |
|
| 13 | - * @link https://github.com/Chronic-Dev/libxml2/blob/683f296a905710ff285c28b8644ef3a3d8be9486/include/libxml/xmlerror.h#L257 |
|
| 14 | - */ |
|
| 15 | - const XML_UNKNOWN_TAG_ERROR_CODE = 801; |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * @var Matcher |
|
| 19 | - */ |
|
| 20 | - private $elementMatcher; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @param Matcher $elementMatcher |
|
| 24 | - * |
|
| 25 | - * @return self |
|
| 26 | - */ |
|
| 27 | - public static function htmlPiece( Matcher $elementMatcher = null ) { |
|
| 28 | - return new static( $elementMatcher ); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - private function __construct( Matcher $elementMatcher = null ) { |
|
| 32 | - $this->elementMatcher = $elementMatcher; |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - public function describeTo( Description $description ) { |
|
| 36 | - $description->appendText( 'valid html piece ' ); |
|
| 37 | - if ( $this->elementMatcher ) { |
|
| 38 | - $description->appendDescriptionOf( $this->elementMatcher ); |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @param string $html |
|
| 44 | - * @param Description $mismatchDescription |
|
| 45 | - * |
|
| 46 | - * @return bool |
|
| 47 | - */ |
|
| 48 | - protected function matchesWithDiagnosticDescription( $html, Description $mismatchDescription ) { |
|
| 49 | - $internalErrors = libxml_use_internal_errors( true ); |
|
| 50 | - $document = new \DOMDocument(); |
|
| 51 | - |
|
| 52 | - $html = $this->escapeScriptTagContents( $html ); |
|
| 53 | - |
|
| 54 | - // phpcs:ignore Generic.PHP.NoSilencedErrors |
|
| 55 | - if ( !@$document->loadHTML( mb_convert_encoding( $html, 'HTML-ENTITIES', 'UTF-8' ) ) ) { |
|
| 56 | - $mismatchDescription->appendText( 'there was some parsing error' ); |
|
| 57 | - return false; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - $errors = libxml_get_errors(); |
|
| 61 | - libxml_clear_errors(); |
|
| 62 | - libxml_use_internal_errors( $internalErrors ); |
|
| 63 | - |
|
| 64 | - $result = true; |
|
| 65 | - /** @var \LibXMLError $error */ |
|
| 66 | - foreach ( $errors as $error ) { |
|
| 67 | - if ( $this->isUnknownTagError( $error ) ) { |
|
| 68 | - continue; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - $mismatchDescription->appendText( 'there was parsing error: ' ) |
|
| 72 | - ->appendText( trim( $error->message ) ) |
|
| 73 | - ->appendText( ' on line ' ) |
|
| 74 | - ->appendText( $error->line ); |
|
| 75 | - $result = false; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - if ( !$result ) { |
|
| 79 | - return false; |
|
| 80 | - } |
|
| 81 | - $mismatchDescription->appendText( 'valid html piece ' ); |
|
| 82 | - |
|
| 83 | - if ( $this->elementMatcher ) { |
|
| 84 | - $result = $this->elementMatcher->matches( $document ); |
|
| 85 | - $this->elementMatcher->describeMismatch( $document, $mismatchDescription ); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $mismatchDescription->appendText( "\nActual html:\n" )->appendText( $html ); |
|
| 89 | - |
|
| 90 | - return $result; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @param \LibXMLError $error |
|
| 95 | - * |
|
| 96 | - * @return bool |
|
| 97 | - */ |
|
| 98 | - private function isUnknownTagError( \LibXMLError $error ) { |
|
| 99 | - return $error->code === self::XML_UNKNOWN_TAG_ERROR_CODE; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param string $html |
|
| 104 | - * |
|
| 105 | - * @return string HTML |
|
| 106 | - */ |
|
| 107 | - private function escapeScriptTagContents( $html ) { |
|
| 108 | - return preg_replace_callback( '#(<script.*>)(.*)(</script>)#isU', function ( $matches ) { |
|
| 109 | - return $matches[1] . str_replace( '</', '<\/', $matches[2] ) . $matches[3]; |
|
| 110 | - }, $html ); |
|
| 111 | - } |
|
| 11 | + /** |
|
| 12 | + * @link http://www.xmlsoft.org/html/libxml-xmlerror.html#xmlParserErrors |
|
| 13 | + * @link https://github.com/Chronic-Dev/libxml2/blob/683f296a905710ff285c28b8644ef3a3d8be9486/include/libxml/xmlerror.h#L257 |
|
| 14 | + */ |
|
| 15 | + const XML_UNKNOWN_TAG_ERROR_CODE = 801; |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * @var Matcher |
|
| 19 | + */ |
|
| 20 | + private $elementMatcher; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @param Matcher $elementMatcher |
|
| 24 | + * |
|
| 25 | + * @return self |
|
| 26 | + */ |
|
| 27 | + public static function htmlPiece( Matcher $elementMatcher = null ) { |
|
| 28 | + return new static( $elementMatcher ); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + private function __construct( Matcher $elementMatcher = null ) { |
|
| 32 | + $this->elementMatcher = $elementMatcher; |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + public function describeTo( Description $description ) { |
|
| 36 | + $description->appendText( 'valid html piece ' ); |
|
| 37 | + if ( $this->elementMatcher ) { |
|
| 38 | + $description->appendDescriptionOf( $this->elementMatcher ); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @param string $html |
|
| 44 | + * @param Description $mismatchDescription |
|
| 45 | + * |
|
| 46 | + * @return bool |
|
| 47 | + */ |
|
| 48 | + protected function matchesWithDiagnosticDescription( $html, Description $mismatchDescription ) { |
|
| 49 | + $internalErrors = libxml_use_internal_errors( true ); |
|
| 50 | + $document = new \DOMDocument(); |
|
| 51 | + |
|
| 52 | + $html = $this->escapeScriptTagContents( $html ); |
|
| 53 | + |
|
| 54 | + // phpcs:ignore Generic.PHP.NoSilencedErrors |
|
| 55 | + if ( !@$document->loadHTML( mb_convert_encoding( $html, 'HTML-ENTITIES', 'UTF-8' ) ) ) { |
|
| 56 | + $mismatchDescription->appendText( 'there was some parsing error' ); |
|
| 57 | + return false; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + $errors = libxml_get_errors(); |
|
| 61 | + libxml_clear_errors(); |
|
| 62 | + libxml_use_internal_errors( $internalErrors ); |
|
| 63 | + |
|
| 64 | + $result = true; |
|
| 65 | + /** @var \LibXMLError $error */ |
|
| 66 | + foreach ( $errors as $error ) { |
|
| 67 | + if ( $this->isUnknownTagError( $error ) ) { |
|
| 68 | + continue; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + $mismatchDescription->appendText( 'there was parsing error: ' ) |
|
| 72 | + ->appendText( trim( $error->message ) ) |
|
| 73 | + ->appendText( ' on line ' ) |
|
| 74 | + ->appendText( $error->line ); |
|
| 75 | + $result = false; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + if ( !$result ) { |
|
| 79 | + return false; |
|
| 80 | + } |
|
| 81 | + $mismatchDescription->appendText( 'valid html piece ' ); |
|
| 82 | + |
|
| 83 | + if ( $this->elementMatcher ) { |
|
| 84 | + $result = $this->elementMatcher->matches( $document ); |
|
| 85 | + $this->elementMatcher->describeMismatch( $document, $mismatchDescription ); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $mismatchDescription->appendText( "\nActual html:\n" )->appendText( $html ); |
|
| 89 | + |
|
| 90 | + return $result; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @param \LibXMLError $error |
|
| 95 | + * |
|
| 96 | + * @return bool |
|
| 97 | + */ |
|
| 98 | + private function isUnknownTagError( \LibXMLError $error ) { |
|
| 99 | + return $error->code === self::XML_UNKNOWN_TAG_ERROR_CODE; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param string $html |
|
| 104 | + * |
|
| 105 | + * @return string HTML |
|
| 106 | + */ |
|
| 107 | + private function escapeScriptTagContents( $html ) { |
|
| 108 | + return preg_replace_callback( '#(<script.*>)(.*)(</script>)#isU', function ( $matches ) { |
|
| 109 | + return $matches[1] . str_replace( '</', '<\/', $matches[2] ) . $matches[3]; |
|
| 110 | + }, $html ); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | 113 | } |
@@ -24,18 +24,18 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @return self |
| 26 | 26 | */ |
| 27 | - public static function htmlPiece( Matcher $elementMatcher = null ) { |
|
| 28 | - return new static( $elementMatcher ); |
|
| 27 | + public static function htmlPiece(Matcher $elementMatcher = null) { |
|
| 28 | + return new static($elementMatcher); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - private function __construct( Matcher $elementMatcher = null ) { |
|
| 31 | + private function __construct(Matcher $elementMatcher = null) { |
|
| 32 | 32 | $this->elementMatcher = $elementMatcher; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - public function describeTo( Description $description ) { |
|
| 36 | - $description->appendText( 'valid html piece ' ); |
|
| 37 | - if ( $this->elementMatcher ) { |
|
| 38 | - $description->appendDescriptionOf( $this->elementMatcher ); |
|
| 35 | + public function describeTo(Description $description) { |
|
| 36 | + $description->appendText('valid html piece '); |
|
| 37 | + if ($this->elementMatcher) { |
|
| 38 | + $description->appendDescriptionOf($this->elementMatcher); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
@@ -45,47 +45,47 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @return bool |
| 47 | 47 | */ |
| 48 | - protected function matchesWithDiagnosticDescription( $html, Description $mismatchDescription ) { |
|
| 49 | - $internalErrors = libxml_use_internal_errors( true ); |
|
| 48 | + protected function matchesWithDiagnosticDescription($html, Description $mismatchDescription) { |
|
| 49 | + $internalErrors = libxml_use_internal_errors(true); |
|
| 50 | 50 | $document = new \DOMDocument(); |
| 51 | 51 | |
| 52 | - $html = $this->escapeScriptTagContents( $html ); |
|
| 52 | + $html = $this->escapeScriptTagContents($html); |
|
| 53 | 53 | |
| 54 | 54 | // phpcs:ignore Generic.PHP.NoSilencedErrors |
| 55 | - if ( !@$document->loadHTML( mb_convert_encoding( $html, 'HTML-ENTITIES', 'UTF-8' ) ) ) { |
|
| 56 | - $mismatchDescription->appendText( 'there was some parsing error' ); |
|
| 55 | + if (!@$document->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'))) { |
|
| 56 | + $mismatchDescription->appendText('there was some parsing error'); |
|
| 57 | 57 | return false; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | $errors = libxml_get_errors(); |
| 61 | 61 | libxml_clear_errors(); |
| 62 | - libxml_use_internal_errors( $internalErrors ); |
|
| 62 | + libxml_use_internal_errors($internalErrors); |
|
| 63 | 63 | |
| 64 | 64 | $result = true; |
| 65 | 65 | /** @var \LibXMLError $error */ |
| 66 | - foreach ( $errors as $error ) { |
|
| 67 | - if ( $this->isUnknownTagError( $error ) ) { |
|
| 66 | + foreach ($errors as $error) { |
|
| 67 | + if ($this->isUnknownTagError($error)) { |
|
| 68 | 68 | continue; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - $mismatchDescription->appendText( 'there was parsing error: ' ) |
|
| 72 | - ->appendText( trim( $error->message ) ) |
|
| 73 | - ->appendText( ' on line ' ) |
|
| 74 | - ->appendText( $error->line ); |
|
| 71 | + $mismatchDescription->appendText('there was parsing error: ') |
|
| 72 | + ->appendText(trim($error->message)) |
|
| 73 | + ->appendText(' on line ') |
|
| 74 | + ->appendText($error->line); |
|
| 75 | 75 | $result = false; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - if ( !$result ) { |
|
| 78 | + if (!$result) { |
|
| 79 | 79 | return false; |
| 80 | 80 | } |
| 81 | - $mismatchDescription->appendText( 'valid html piece ' ); |
|
| 81 | + $mismatchDescription->appendText('valid html piece '); |
|
| 82 | 82 | |
| 83 | - if ( $this->elementMatcher ) { |
|
| 84 | - $result = $this->elementMatcher->matches( $document ); |
|
| 85 | - $this->elementMatcher->describeMismatch( $document, $mismatchDescription ); |
|
| 83 | + if ($this->elementMatcher) { |
|
| 84 | + $result = $this->elementMatcher->matches($document); |
|
| 85 | + $this->elementMatcher->describeMismatch($document, $mismatchDescription); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - $mismatchDescription->appendText( "\nActual html:\n" )->appendText( $html ); |
|
| 88 | + $mismatchDescription->appendText("\nActual html:\n")->appendText($html); |
|
| 89 | 89 | |
| 90 | 90 | return $result; |
| 91 | 91 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * |
| 96 | 96 | * @return bool |
| 97 | 97 | */ |
| 98 | - private function isUnknownTagError( \LibXMLError $error ) { |
|
| 98 | + private function isUnknownTagError(\LibXMLError $error) { |
|
| 99 | 99 | return $error->code === self::XML_UNKNOWN_TAG_ERROR_CODE; |
| 100 | 100 | } |
| 101 | 101 | |
@@ -104,10 +104,10 @@ discard block |
||
| 104 | 104 | * |
| 105 | 105 | * @return string HTML |
| 106 | 106 | */ |
| 107 | - private function escapeScriptTagContents( $html ) { |
|
| 108 | - return preg_replace_callback( '#(<script.*>)(.*)(</script>)#isU', function ( $matches ) { |
|
| 109 | - return $matches[1] . str_replace( '</', '<\/', $matches[2] ) . $matches[3]; |
|
| 110 | - }, $html ); |
|
| 107 | + private function escapeScriptTagContents($html) { |
|
| 108 | + return preg_replace_callback('#(<script.*>)(.*)(</script>)#isU', function($matches) { |
|
| 109 | + return $matches[1] . str_replace('</', '<\/', $matches[2]) . $matches[3]; |
|
| 110 | + }, $html); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | } |