Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if ($this->nodesToRemoveCollector->isActive()) {
return null;
}

$node = $this->resolveCurrentStatement($node);

if (! in_array($node::class, self::STMTS_TO_HAVE_NEXT_NEWLINE, true)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Rector\Core\Tests\Issues\Issue6840;

use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;

/**
* @see https://github.com/rectorphp/rector/issues/6840
*/
final class ClassPropertyPromotionAndNewLineAfterStatementRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}

/**
* @return Iterator<SmartFileInfo>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
31 changes: 31 additions & 0 deletions tests/Issues/Issue6840/Fixture/fixture.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Rector\Core\Tests\Issues\Issue6840\Fixture;

class Fixture
{
protected string $imageId;
protected array $imageSize;

public function __construct($imageId)
{
$this->imageId = $imageId;
$this->imageSize = [];
}
}
?>
-----
<?php

namespace Rector\Core\Tests\Issues\Issue6840\Fixture;

class Fixture
{
protected array $imageSize;

public function __construct(protected $imageId)
{
$this->imageSize = [];
}
}
?>
13 changes: 13 additions & 0 deletions tests/Issues/Issue6840/config/configured_rule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(ClassPropertyAssignToConstructorPromotionRector::class);
$services->set(NewlineAfterStatementRector::class);
};