Skip to content

Commit

Permalink
Merge pull request #331 from tighten/adc/fix-space-between
Browse files Browse the repository at this point in the history
Fix issue with anon classes
  • Loading branch information
driftingly authored Jan 27, 2023
2 parents e0d890d + 9e320c3 commit ad05fc2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Formatters/OneLineBetweenClassVisibilityChanges.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public function beforeTraverse(array $nodes)

public function enterNode(Node $node)
{
if ($node instanceof Node\Stmt\Class_) {
$this->previousNode = null;

return null;
}

if (! $node instanceof ClassConst && ! $node instanceof Property) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,53 @@ class Thing

$this->assertSame($file, $formatted);
}

/** @test */
public function catches_missing_line_between_visibility_changes_in_anon_class()
{
$file = <<<'file'
<?php
namespace App;
class Thing
{
public $test;
public function getThing(): NodeVisitorAbstract
{
return new class extends NodeVisitorAbstract
{
protected const OK = 1;
private $ok;
};
}
}
file;

$expected = <<<'file'
<?php
namespace App;
class Thing
{
public $test;
public function getThing(): NodeVisitorAbstract
{
return new class extends NodeVisitorAbstract
{
protected const OK = 1;
private $ok;
};
}
}
file;

$formatted = (new TFormat)->format(new OneLineBetweenClassVisibilityChanges($file));

$this->assertSame($expected, $formatted);
}
}

0 comments on commit ad05fc2

Please sign in to comment.