From 4c7ccdf98092d64ff999480393f5c8469b476839 Mon Sep 17 00:00:00 2001 From: Fred Emmott Date: Fri, 12 Jul 2019 15:17:31 -0700 Subject: [PATCH] Use is expressions instead of insteadof --- .travis.yml | 3 +- composer.json | 2 +- src/inlines/Emphasis.php | 8 ++-- src/inlines/_Private/parse_with_blacklist.php | 2 +- src/render/HTMLRenderer.php | 14 +++--- src/render/MarkdownRenderer.php | 16 +++---- src/render/Renderer.php | 48 +++++++++---------- src/render/TagFilterExtension.php | 4 +- src/unparsed-blocks/BlockQuote.php | 4 +- src/unparsed-blocks/ContainerBlock.php | 2 +- src/unparsed-blocks/ListItem.php | 2 +- 11 files changed, 52 insertions(+), 53 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7cdd738..c45e8c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,7 @@ sudo: required language: generic services: docker env: -- HHVM_VERSION=4.1-latest -- HHVM_VERSION=4.2-latest +- HHVM_VERSION=4.13-latest - HHVM_VERSION=latest - HHVM_VERSION=nightly install: diff --git a/composer.json b/composer.json index 181f546..49df6ce 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } }, "require": { - "hhvm": "^4.0", + "hhvm": "^4.13", "hhvm/hsl": "^4.0", "hhvm/type-assert": "^3.1" }, diff --git a/src/inlines/Emphasis.php b/src/inlines/Emphasis.php index 165dae2..be33d2b 100644 --- a/src/inlines/Emphasis.php +++ b/src/inlines/Emphasis.php @@ -190,7 +190,7 @@ private static function processEmphasis( $position = $closer_idx; $closer = $stack[$closer_idx]; invariant( - $closer instanceof Stack\DelimiterNode, + $closer is Stack\DelimiterNode, 'closer must be a delimiter', ); list($closer_text, $closer_flags) = tuple( @@ -203,7 +203,7 @@ private static function processEmphasis( $bottom = $openers_bottom[$char][$closer_len]; for ($i = $position - 1; $i >= $bottom; $i--) { $item = $stack[$i]; - if (!$item instanceof Stack\DelimiterNode) { + if (!$item is Stack\DelimiterNode) { continue; } if (!($item->getFlags() & self::IS_START)) { @@ -329,7 +329,7 @@ private static function findCloser( $offset = C\find_key( $in, $item ==> - $item instanceof Stack\DelimiterNode + $item is Stack\DelimiterNode && $item->getFlags() & self::IS_END, ); if ($offset === null) { @@ -493,6 +493,6 @@ private static function isStartOfRun( Str\slice($markdown, 0, $offset), ); - return C\last($previous) instanceof BackslashEscape; + return C\last($previous) is BackslashEscape; } } diff --git a/src/inlines/_Private/parse_with_blacklist.php b/src/inlines/_Private/parse_with_blacklist.php index 04ceff4..2433eb4 100644 --- a/src/inlines/_Private/parse_with_blacklist.php +++ b/src/inlines/_Private/parse_with_blacklist.php @@ -45,7 +45,7 @@ function parse_with_blacklist ( \get_class($inline), ); $offset = $new_offset; - if ($inline instanceof Inlines\InlineSequence) { + if ($inline is Inlines\InlineSequence) { $out = Vec\concat($out, $inline->getChildren()); } else { $out[] = $inline; diff --git a/src/render/HTMLRenderer.php b/src/render/HTMLRenderer.php index 3e2e270..8fca1ff 100644 --- a/src/render/HTMLRenderer.php +++ b/src/render/HTMLRenderer.php @@ -70,7 +70,7 @@ protected function renderNodes(vec $nodes): string { <<__Override>> protected function renderResolvedNode(ASTNode $node): string { - if ($node instanceof RenderableAsHTML) { + if ($node is RenderableAsHTML) { return $node->renderAsHTML($this->getContext(), $this); } return parent::renderResolvedNode($node); @@ -132,7 +132,7 @@ protected function renderTaskListItemExtension( $children = $item->getChildren(); $first = C\first($children); - if ($first instanceof Blocks\Paragraph) { + if ($first is Blocks\Paragraph) { $children[0] = new Blocks\Paragraph( Vec\concat( vec[new Inlines\RawHTML($checkbox)], @@ -159,7 +159,7 @@ protected function renderListItem( Blocks\ListOfItems $list, Blocks\ListItem $item, ): string { - if ($item instanceof Blocks\TaskListItemExtension) { + if ($item is Blocks\TaskListItemExtension) { return $this->renderTaskListItemExtension($list, $item); } @@ -171,7 +171,7 @@ protected function renderListItem( $content = ''; if ($list->isTight()) { - if (!C\first($children) instanceof Blocks\Paragraph) { + if (!C\first($children) is Blocks\Paragraph) { $content .= "\n"; } @@ -179,17 +179,17 @@ protected function renderListItem( |> Vec\map( $$, $child ==> { - if ($child instanceof Blocks\Paragraph) { + if ($child is Blocks\Paragraph) { return $this->renderNodes($child->getContents()); } - if ($child instanceof Blocks\Block) { + if ($child is Blocks\Block) { return Str\trim($this->render($child)); } return $this->render($child); }, ) |> Str\join($$, "\n"); - if (!C\last($children) instanceof Blocks\Paragraph) { + if (!C\last($children) is Blocks\Paragraph) { $content .= "\n"; } } else { diff --git a/src/render/MarkdownRenderer.php b/src/render/MarkdownRenderer.php index 11d6770..c07bb55 100644 --- a/src/render/MarkdownRenderer.php +++ b/src/render/MarkdownRenderer.php @@ -29,7 +29,7 @@ protected function renderNodes(vec $nodes): string { $$, $node ==> { $content = $this->render($node); - if ($node instanceof Blocks\Block) { + if ($node is Blocks\Block) { $content = $content."\n\n"; } $this->outContext .= $content; @@ -161,7 +161,7 @@ protected function renderListItem( } $leading = Str\length($sep); - if ($item instanceof Blocks\TaskListItemExtension) { + if ($item is Blocks\TaskListItemExtension) { $sep .= \sprintf('[%s] ', $item->isChecked() ? 'x' : ' '); } @@ -174,10 +174,10 @@ protected function renderListItem( |> Vec\map( $$, $child ==> { - if ($child instanceof Blocks\Paragraph) { + if ($child is Blocks\Paragraph) { return $this->renderNodes($child->getContents()); } - if ($child instanceof Blocks\Block) { + if ($child is Blocks\Block) { return Str\trim($this->render($child)); } return $this->render($child); @@ -219,7 +219,7 @@ protected function renderParagraph(Blocks\Paragraph $node): string { $$, $line ==> { $parsed = UnparsedBlocks\parse($ctx, $line)->getChildren(); - if (!C\firstx($parsed) instanceof UnparsedBlocks\Paragraph) { + if (!C\firstx($parsed) is UnparsedBlocks\Paragraph) { return " ".$line; } if (\preg_match('/^ {0,3}[=-]+ *$/', $line)) { @@ -293,7 +293,7 @@ protected function renderThematicBreak(): string { <<__Override>> protected function renderAutoLink(Inlines\AutoLink $node): string { - if ($node instanceof Inlines\AutoLinkExtension) { + if ($node is Inlines\AutoLinkExtension) { return $node->getText(); } return '<'.$node->getText().'>'; @@ -303,10 +303,10 @@ protected function renderAutoLink(Inlines\AutoLink $node): string { protected function renderInlineWithPlainTextContent( Inlines\InlineWithPlainTextContent $node, ): string { - if ($node instanceof Inlines\BackslashEscape) { + if ($node is Inlines\BackslashEscape) { return "\\".$node->getContent(); } - if ($node instanceof Inlines\EntityReference) { + if ($node is Inlines\EntityReference) { // This matters if the entity reference is for whitespace: if we print // it out raw, we might accidentally create an indented code block, or // continue a more deeply nested block than we should. diff --git a/src/render/Renderer.php b/src/render/Renderer.php index ffe6ea9..a06720c 100644 --- a/src/render/Renderer.php +++ b/src/render/Renderer.php @@ -70,61 +70,61 @@ abstract protected function renderStrikethroughExtension( protected function renderResolvedNode( ASTNode $node, ): T { - if ($node instanceof Blocks\BlankLine) { + if ($node is Blocks\BlankLine) { return $this->renderBlankLine(); } - if ($node instanceof Blocks\BlockQuote) { + if ($node is Blocks\BlockQuote) { return $this->renderBlockQuote($node); } - if ($node instanceof Blocks\BlockSequence) { + if ($node is Blocks\BlockSequence) { return $this->renderNodes($node->getChildren()); } - if ($node instanceof Blocks\Document) { + if ($node is Blocks\Document) { return $this->renderDocument($node); } // Blocks\FencedCodeBlock // Blocks\IndentedCodeBlock - if ($node instanceof Blocks\CodeBlock) { + if ($node is Blocks\CodeBlock) { return $this->renderCodeBlock($node); } - if ($node instanceof Blocks\Heading) { + if ($node is Blocks\Heading) { return $this->renderHeading($node); } - if ($node instanceof Blocks\HTMLBlock) { + if ($node is Blocks\HTMLBlock) { return $this->renderHTMLBlock($node); } - if ($node instanceof Blocks\InlineSequenceBlock) { + if ($node is Blocks\InlineSequenceBlock) { return $this->renderNodes($node->getChildren()); } - if ($node instanceof Blocks\LinkReferenceDefinition) { + if ($node is Blocks\LinkReferenceDefinition) { return $this->renderLinkReferenceDefinition($node); } - if ($node instanceof Blocks\ListOfItems) { + if ($node is Blocks\ListOfItems) { return $this->renderListOfItems($node); } - if ($node instanceof Blocks\Paragraph) { + if ($node is Blocks\Paragraph) { return $this->renderParagraph($node); } - if ($node instanceof Blocks\TableExtension) { + if ($node is Blocks\TableExtension) { return $this->renderTableExtension($node); } - if ($node instanceof Blocks\ThematicBreak) { + if ($node is Blocks\ThematicBreak) { return $this->renderThematicBreak(); } - if ($node instanceof Inlines\AutoLink) { + if ($node is Inlines\AutoLink) { return $this->renderAutoLink($node); } @@ -132,43 +132,43 @@ protected function renderResolvedNode( // Inlines\DisallowedRawHTML // Inlines\EntityReference // Inlines\TextualContent - if ($node instanceof Inlines\InlineWithPlainTextContent) { + if ($node is Inlines\InlineWithPlainTextContent) { return $this->renderInlineWithPlainTextContent($node); } - if ($node instanceof Inlines\CodeSpan) { + if ($node is Inlines\CodeSpan) { return $this->renderCodeSpan($node); } - if ($node instanceof Inlines\Emphasis) { + if ($node is Inlines\Emphasis) { return $this->renderEmphasis($node); } - if ($node instanceof Inlines\HardLineBreak) { + if ($node is Inlines\HardLineBreak) { return $this->renderHardLineBreak(); } - if ($node instanceof Inlines\Image) { + if ($node is Inlines\Image) { return $this->renderImage($node); } - if ($node instanceof Inlines\InlineSequence) { + if ($node is Inlines\InlineSequence) { return $this->renderNodes($node->getChildren()); } - if ($node instanceof Inlines\Link) { + if ($node is Inlines\Link) { return $this->renderLink($node); } - if ($node instanceof Inlines\RawHTML) { + if ($node is Inlines\RawHTML) { return $this->renderRawHTML($node); } - if ($node instanceof Inlines\SoftLineBreak) { + if ($node is Inlines\SoftLineBreak) { return $this->renderSoftLineBreak(); } - if ($node instanceof Inlines\StrikethroughExtension) { + if ($node is Inlines\StrikethroughExtension) { return $this->renderStrikethroughExtension($node); } diff --git a/src/render/TagFilterExtension.php b/src/render/TagFilterExtension.php index 69f0b97..ec35382 100644 --- a/src/render/TagFilterExtension.php +++ b/src/render/TagFilterExtension.php @@ -18,10 +18,10 @@ public function filter( RenderContext $_context, ASTNode $node, ): vec { - if ($node instanceof Blocks\HTMLBlock) { + if ($node is Blocks\HTMLBlock) { return vec[$this->filterHTMLBlock($node)]; } - if ($node instanceof Inlines\RawHTML) { + if ($node is Inlines\RawHTML) { return vec[$this->filterInlineHTML($node)]; } return vec[$node]; diff --git a/src/unparsed-blocks/BlockQuote.php b/src/unparsed-blocks/BlockQuote.php index 75f8b1d..010c5cd 100644 --- a/src/unparsed-blocks/BlockQuote.php +++ b/src/unparsed-blocks/BlockQuote.php @@ -61,10 +61,10 @@ public static function consume( protected static function endsWithParagraph( Block $block, ): bool { - if ($block instanceof Paragraph) { + if ($block is Paragraph) { return true; } - if ($block instanceof ContainerBlock) { + if ($block is ContainerBlock<_>) { $last = C\lastx($block->getChildren()); return self::endsWithParagraph($last); } diff --git a/src/unparsed-blocks/ContainerBlock.php b/src/unparsed-blocks/ContainerBlock.php index 5c354a8..59ac7e5 100644 --- a/src/unparsed-blocks/ContainerBlock.php +++ b/src/unparsed-blocks/ContainerBlock.php @@ -38,7 +38,7 @@ protected static function consumeChildren( \get_class($child), $lines->getFirstLine(), ); - if ($child instanceof BlockSequence) { + if ($child is BlockSequence) { $children = Vec\concat($children, $child->getChildren()); } else { $children[] = $child; diff --git a/src/unparsed-blocks/ListItem.php b/src/unparsed-blocks/ListItem.php index e1e9d76..50255ee 100644 --- a/src/unparsed-blocks/ListItem.php +++ b/src/unparsed-blocks/ListItem.php @@ -43,7 +43,7 @@ public function getNumber(): ?int { } public function makesListLoose(): bool { - return C\any($this->children, $child ==> $child instanceof BlankLine); + return C\any($this->children, $child ==> $child is BlankLine); } public static function consume(