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

Commit

Permalink
Remove direct usage of static locals
Browse files Browse the repository at this point in the history
  • Loading branch information
fredemmott committed Mar 26, 2019
1 parent 4aec37d commit 7d96922
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
1 change: 1 addition & 0 deletions .hhconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
assume_php=false
disable_static_local_variables = true
ignored_paths = [ "vendor/.+/tests/.+" ]
disallow_elvis_space=true
disallow_non_arraykey_keys=true
Expand Down
22 changes: 11 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 25 additions & 23 deletions src/render/MarkdownRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,7 @@ protected function renderLinkReferenceDefinition(
// reference definitions when constructing the AST; keeping them in case
// this is mixed with other markdown, or if we end up creating a separate
// ReferenceLink AST node that renderers need to deal with.
$md = \sprintf(
'[%s]: <%s>',
$def->getLabel(),
$def->getDestination(),
);
$md = \sprintf('[%s]: <%s>', $def->getLabel(), $def->getDestination());
$title = $def->getTitle();
if ($title === null) {
return $md;
Expand Down Expand Up @@ -171,23 +167,23 @@ protected function renderListItem(

if ($list->isLoose()) {
$content = $item->getChildren()
|> $this->renderNodes($$)
|> $$."\n";
|> $this->renderNodes($$)
|> $$."\n";
} else {
$content = $item->getChildren()
|> Vec\map(
$$,
$child ==> {
if ($child instanceof Blocks\Paragraph) {
return $this->renderNodes($child->getContents());
}
if ($child instanceof Blocks\Block) {
return Str\trim($this->render($child));
}
return $this->render($child);
},
)
|> Str\join($$, "\n");
if ($child instanceof Blocks\Paragraph) {
return $this->renderNodes($child->getContents());
}
if ($child instanceof Blocks\Block) {
return Str\trim($this->render($child));
}
return $this->render($child);
},
)
|> Str\join($$, "\n");
}
return $content
|> Str\split($$, "\n")
Expand All @@ -200,12 +196,16 @@ protected function renderListItem(
|> $sep.$$;
}

private int $numberOfLists = 0;

<<__Override>>
protected function renderListOfItems(Blocks\ListOfItems $node): string {
static $list_count = 0;
++$list_count;
++$this->numberOfLists;
return $node->getItems()
|> Vec\map($$, $item ==> $this->renderListItem($list_count, $node, $item))
|> Vec\map(
$$,
$item ==> $this->renderListItem($this->numberOfLists, $node, $item),
)
|> Str\join($$, "\n");
}

Expand Down Expand Up @@ -322,15 +322,15 @@ protected function renderInlineWithPlainTextContent(
<<__Override>>
protected function renderCodeSpan(Inlines\CodeSpan $node): string {
$code = $node->getCode();
$len = Str\length((string) $this->outContext) + Str\length($code);
$len = Str\length((string)$this->outContext) + Str\length($code);

$sep = '`';
for ($sep_len = 1; $sep_len <= $len + 1; ++$sep_len) {
$sep = Str\repeat('`', $sep_len);
if (Str\contains($code, $sep)) {
continue;
}
if (Str\contains((string) $this->outContext, $sep)) {
if (Str\contains((string)$this->outContext, $sep)) {
continue;
}
break;
Expand Down Expand Up @@ -399,7 +399,9 @@ protected function renderSoftLineBreak(): string {
}

<<__Override>>
protected function renderStrikethroughExtension(Inlines\StrikethroughExtension $node): string {
protected function renderStrikethroughExtension(
Inlines\StrikethroughExtension $node,
): string {
$children = $node->getChildren()
|> Vec\map($$, $child ==> $this->render($child))
|> Str\join($$, '');
Expand Down

0 comments on commit 7d96922

Please sign in to comment.