mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-21 16:02:23 +02:00
[PSR-4] Fix declare for NormalizeNamespaceByPSR4ComposerAutoloadFileSystemRector (#4332)
This commit is contained in:
parent
a71d3d2d2b
commit
7a5cf0ed5a
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Rector\PSR4\Rector\FileSystem;
|
||||
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Stmt\Declare_;
|
||||
use PhpParser\Node\Stmt\Namespace_;
|
||||
use Rector\Autodiscovery\ValueObject\NodesWithFileDestination;
|
||||
use Rector\Core\RectorDefinition\ComposerJsonAwareCodeSample;
|
||||
@ -86,12 +87,25 @@ CODE_SAMPLE
|
||||
return;
|
||||
}
|
||||
|
||||
$nodesWithStrictTypesThenNamespace = [];
|
||||
foreach ($nodes as $key => $node) {
|
||||
if ($node instanceof Declare_) {
|
||||
$nodesWithStrictTypesThenNamespace[] = $node;
|
||||
unset($nodes[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$namespace = new Namespace_(new Name($expectedNamespace));
|
||||
$namespace->stmts = $nodes;
|
||||
|
||||
$nodesWithFileDestination = new NodesWithFileDestination([
|
||||
$namespace,
|
||||
], $smartFileInfo->getRealPath(), $smartFileInfo);
|
||||
$nodesWithStrictTypesThenNamespace[] = $namespace;
|
||||
|
||||
$nodesWithFileDestination = new NodesWithFileDestination(
|
||||
$nodesWithStrictTypesThenNamespace,
|
||||
$smartFileInfo->getRealPath(),
|
||||
$smartFileInfo
|
||||
);
|
||||
|
||||
$this->printNodesWithFileDestination($nodesWithFileDestination);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
class NamespaceLessClass
|
||||
{
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace Rector\PSR4\Tests\Rector\FileSystem\NormalizeNamespaceByPSR4ComposerAutoloadFileSystemRector\Fixture;
|
||||
|
||||
class NamespaceLessClass
|
||||
|
Loading…
x
Reference in New Issue
Block a user