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
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;
}
Comment on lines 54 to +59
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved to AbstractRector::beforeTraverse() or similar, as rector rule itself should not decide about the sip.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't, as AbstractRector::beforeTraverse() on setup File object, and re-called early in current parent::beforeTraverse(), moving to AbstractRector will require parent::beforeTraverse() to not called early, but after.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Let's go for it now then.
Bbut in case more rules will need the skip fix, we'll have to move it to single place outside specific rules.


$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