Skip to content
This repository has been archived by the owner on Jul 1, 2023. It is now read-only.

Commit

Permalink
Use is expressions instead of insteadof
Browse files Browse the repository at this point in the history
  • Loading branch information
fredemmott committed Jul 12, 2019
1 parent 2701e2e commit 4c7ccdf
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 53 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
},
"require": {
"hhvm": "^4.0",
"hhvm": "^4.13",
"hhvm/hsl": "^4.0",
"hhvm/type-assert": "^3.1"
},
Expand Down
8 changes: 4 additions & 4 deletions src/inlines/Emphasis.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/inlines/_Private/parse_with_blacklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/render/HTMLRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function renderNodes(vec<ASTNode> $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);
Expand Down Expand Up @@ -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)],
Expand All @@ -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);
}

Expand All @@ -171,25 +171,25 @@ protected function renderListItem(
$content = '';

if ($list->isTight()) {
if (!C\first($children) instanceof Blocks\Paragraph) {
if (!C\first($children) is Blocks\Paragraph) {
$content .= "\n";
}

$content .= $children
|> 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 {
Expand Down
16 changes: 8 additions & 8 deletions src/render/MarkdownRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function renderNodes(vec<ASTNode> $nodes): string {
$$,
$node ==> {
$content = $this->render($node);
if ($node instanceof Blocks\Block) {
if ($node is Blocks\Block) {
$content = $content."\n\n";
}
$this->outContext .= $content;
Expand Down Expand Up @@ -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' : ' ');
}

Expand All @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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().'>';
Expand All @@ -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.
Expand Down
48 changes: 24 additions & 24 deletions src/render/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,105 +70,105 @@ 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);
}

// Inlines\BackslashEscape
// 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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/render/TagFilterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public function filter(
RenderContext $_context,
ASTNode $node,
): vec<ASTNode> {
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];
Expand Down
4 changes: 2 additions & 2 deletions src/unparsed-blocks/BlockQuote.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/unparsed-blocks/ContainerBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/unparsed-blocks/ListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 4c7ccdf

Please sign in to comment.