Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed use statement aggregation to only look at consecutive runs in…

…stead of all use statements in the block.
  • Loading branch information...
commit aa384531bcab779af0fc25552287866b470ece00 1 parent 824c2fc
@jmalloc jmalloc authored
View
33 lib/Icecave/Rasta/Renderer.php
@@ -176,30 +176,35 @@ public function visitIdentifier(Identifier $node)
public function visitPhpBlock(PhpBlock $node, $closeTag = true)
{
+ $code = '';
+
$useStatements = array();
- $otherCode = '';
+ $flushUseStatements = function () use (&$useStatements, &$code) {
+ if ($useStatements) {
+ sort($useStatements);
+ $code .= implode('', $useStatements);
+ $code .= $this->newlineString;
+ $useStatements = array();
+ }
+ };
+
+ $code .= '<?';
+ if (!$node->isShortTag()) {
+ $code .= 'php';
+ }
+ $code .= $this->newlineString;
foreach ($node->children() as $child) {
if ($child instanceof UseStatement) {
$useStatements[] = $child->accept($this);
} else {
- $otherCode .= $child->accept($this);
+ $flushUseStatements();
+ $code .= $child->accept($this);
}
}
- sort($useStatements);
- $useStatements = implode('', $useStatements);
+ $flushUseStatements();
- $code = '<?';
- if (!$node->isShortTag()) {
- $code .= 'php';
- }
- $code .= $this->newlineString;
- if ($useStatements) {
- $code .= $useStatements;
- $code .= $this->newlineString;
- }
- $code .= $otherCode;
if ($closeTag) {
$code .= '?>';
}
View
7 test/suite/Icecave/Rasta/RendererTest.php
@@ -145,7 +145,7 @@ public function testVisitPhpBlockShortTag()
$this->assertSame('<' . '?' . $this->_newlineString . '?' . '>', $code);
}
- public function testVisitPhpBlockNoUseStatements()
+ public function testVisitPhpBlockWithoutUseStatements()
{
$node = new PhpBlock;
$node->add(new ClassDefinition(new Identifier('Thing')));
@@ -165,8 +165,9 @@ public function testVisitPhpBlockWithUseStatements()
$node = new PhpBlock;
$node->add(new UseStatement(QualifiedIdentifier::fromString('A')));
$node->add(new UseStatement(QualifiedIdentifier::fromString('C')));
- $node->add(new ClassDefinition(new Identifier('Thing')));
$node->add(new UseStatement(QualifiedIdentifier::fromString('B')));
+ $node->add(new ClassDefinition(new Identifier('Thing')));
+ $node->add(new UseStatement(QualifiedIdentifier::fromString('X')));
$code = $node->accept($this->_renderer);
@@ -178,6 +179,8 @@ public function testVisitPhpBlockWithUseStatements()
$expected .= 'class Thing' . $this->_newlineString;
$expected .= '{' . $this->_newlineString;
$expected .= '}' . $this->_newlineString;
+ $expected .= 'use X;' . $this->_newlineString;
+ $expected .= $this->_newlineString;
$expected .= '?' . '>';
$this->assertSame($expected, $code);
}
Please sign in to comment.
Something went wrong with that request. Please try again.