Skip to content

Commit

Permalink
[TypeDeclaration] Handle skipped by file path on DeclareStrictTypesRe…
Browse files Browse the repository at this point in the history
…ctor due to use beforeTraverse() (#5191)
  • Loading branch information
samsonasik authored Oct 23, 2023
1 parent a0d3244 commit 6d5ffbe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector\Fixture;

function skipped_by_path()
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(DeclareStrictTypesRector::class);
$rectorConfig->skip([
DeclareStrictTypesRector::class => [
// .php.inc changed .php during running test
realpath(__DIR__ . '/../Fixture') . '/skipped_by_path.php',
],
]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public function beforeTraverse(array $nodes): ?array
{
parent::beforeTraverse($nodes);

$filePath = $this->file->getFilePath();
if ($this->skipper->shouldSkipElementAndFilePath(self::class, $filePath)) {
return null;
}

$newStmts = $this->file->getNewStmts();

if ($newStmts === []) {
Expand Down
2 changes: 1 addition & 1 deletion src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ abstract class AbstractRector extends NodeVisitorAbstract implements RectorInter

private SimpleCallableNodeTraverser $simpleCallableNodeTraverser;

private Skipper $skipper;
protected Skipper $skipper;

private CurrentFileProvider $currentFileProvider;

Expand Down

0 comments on commit 6d5ffbe

Please sign in to comment.