Skip to content

Commit

Permalink
Class pretty printing prioritizing
Browse files Browse the repository at this point in the history
  • Loading branch information
ajthinking committed May 21, 2022
1 parent cf0e7fb commit 02e6d44
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
8 changes: 2 additions & 6 deletions src/Support/PSR2PrettyPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,13 @@ public function __construct($options = [])
// Fix empty line before class definition
protected function pStmt_Class(Class_ $node)
{
return PHP_EOL . $this->pClassCommon($node, ' ' . $node->name);
return $this->pClassCommon($node, ' ' . $node->name);
}

// Fix empty line before class definition
protected function pStmt_ClassMethod(ClassMethod $node)
{
$comments = $node->getComments();

$ln = $comments ? '' : $this->nl;

return $ln . $this->pAttrGroups($node->attrGroups)
return $this->pAttrGroups($node->attrGroups)
. $this->pModifiers($node->flags)
. 'function ' . ($node->byRef ? '&' : '') . $node->name
. '(' . $this->pMaybeMultiline($node->params) . ')'
Expand Down
17 changes: 16 additions & 1 deletion tests/Feature/PrettyPrintTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Archetype\Tests\Support\Facades\TestablePHPFile as PHPFile;
use PhpParser\BuilderFactory;

test('arrays are beutiful when loaded and rendered', function() {
PHPFile::load('app/Models/User.php')
Expand Down Expand Up @@ -35,5 +36,19 @@
test('created class with use statements have beautiful header'/*, function() {
PHPFile::make()->class()
->use('\TraitX')
->assertProperSpacingInClassHeader()
->preview();
}*/);

test('created and modified class without use statements have beautiful header', function() {
PHPFile::make()->class(App\Dummy::class)
->astQuery()
->class()
->insertStmt(
(new BuilderFactory)->method('myMethod')->getNode()
)
->commit()
->end()
->assertProperSpacingInClassHeader();
}*/);
});

0 comments on commit 02e6d44

Please sign in to comment.