Skip to content

Commit

Permalink
use file provider in AbstractPostRector
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jun 28, 2024
1 parent 367893f commit 64b2f08
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 33 deletions.
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,7 @@ parameters:
-
message: '#Parameter \#4 \$file of method Rector\\NodeTypeResolver\\PhpDocNodeVisitor\\NameImportingPhpDocNodeVisitor\:\:processFqnNameImport\(\) expects Rector\\ValueObject\\Application\\File, Rector\\ValueObject\\Application\\File\|null given#'
path: src/NodeTypeResolver/PhpDocNodeVisitor/NameImportingPhpDocNodeVisitor.php

- '#Parameter (.*?) Rector\\ValueObject\\Application\\File, Rector\\ValueObject\\Application\\File\|null given#'
- '#Cannot call method getFilePath\(\) on Rector\\ValueObject\\Application\\File\|null#'

10 changes: 5 additions & 5 deletions src/PostRector/Rector/AbstractPostRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ abstract class AbstractPostRector extends NodeVisitorAbstract implements PostRec
{
private File|null $file = null;

public function setFile(File $file): void
{
$this->file = $file;
}

/**
* @param Stmt[] $stmts
*/
Expand All @@ -22,11 +27,6 @@ public function shouldTraverse(array $stmts): bool
return true;
}

public function setFile(File $file): void
{
$this->file = $file;
}

public function getFile(): File
{
Assert::isInstanceOf($this->file, File::class);
Expand Down
12 changes: 5 additions & 7 deletions src/PostRector/Rector/DocblockNameImportingPostRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
use PhpParser\Node\Param;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\InlineHTML;
use Rector\Application\Provider\CurrentFileProvider;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockNameImporter;
use Rector\PhpParser\Node\BetterNodeFinder;
use Rector\ValueObject\Application\File;

final class DocblockNameImportingPostRector extends AbstractPostRector
{
Expand All @@ -23,7 +21,6 @@ public function __construct(
private readonly PhpDocInfoFactory $phpDocInfoFactory,
private readonly DocBlockUpdater $docBlockUpdater,
private readonly BetterNodeFinder $betterNodeFinder,
private readonly CurrentFileProvider $currentFileProvider,
) {
}

Expand All @@ -38,10 +35,11 @@ public function enterNode(Node $node): Node|int|null
return null;
}

/** @var File $file */
$file = $this->currentFileProvider->getFile();

$hasDocChanged = $this->docBlockNameImporter->importNames($phpDocInfo->getPhpDocNode(), $node, $file);
$hasDocChanged = $this->docBlockNameImporter->importNames(
$phpDocInfo->getPhpDocNode(),
$node,
$this->getFile()
);
if (! $hasDocChanged) {
return null;
}
Expand Down
21 changes: 0 additions & 21 deletions src/PostRector/Rector/NameImportingPostRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,11 @@
use PhpParser\Node\Stmt\InlineHTML;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Node\Stmt\Use_;
<<<<<<< HEAD
<<<<<<< HEAD
=======
use PhpParser\NodeTraverser;
=======
>>>>>>> 3e387888c4 (add fixture to be skipped)
use Rector\Application\Provider\CurrentFileProvider;
>>>>>>> 56c9567d68 (split docblock name imports and name imports as different scope)
use Rector\CodingStyle\ClassNameImport\ClassNameImportSkipper;
use Rector\CodingStyle\Node\NameImporter;
use Rector\Naming\Naming\AliasNameResolver;
use Rector\Naming\Naming\UseImportsResolver;
use Rector\PhpParser\Node\BetterNodeFinder;
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
use Rector\Exception\ShouldNotHappenException;
use Rector\Naming\Naming\AliasNameResolver;
use Rector\Naming\Naming\UseImportsResolver;
use Rector\PhpParser\Node\CustomNode\FileWithoutNamespace;
>>>>>>> 06a7fb75dd (split docblock name imports and name imports as different scope)
=======
>>>>>>> 3e387888c4 (add fixture to be skipped)
use Rector\ValueObject\Application\File;
>>>>>>> 56c9567d68 (split docblock name imports and name imports as different scope)

final class NameImportingPostRector extends AbstractPostRector
{
Expand Down

0 comments on commit 64b2f08

Please sign in to comment.