1111use Rector \PhpParser \Node \FileNode ;
1212use Rector \Rector \AbstractRector ;
1313use Rector \TypeDeclaration \NodeAnalyzer \DeclareStrictTypeFinder ;
14- use Rector \ValueObject \Application \File ;
1514use Rector \ValueObject \PhpVersion ;
1615use Rector \VersionBonding \Contract \MinPhpVersionInterface ;
1716use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
@@ -64,14 +63,12 @@ function someFunction(int $number)
6463 */
6564 public function refactor (Node $ node ): ?FileNode
6665 {
67- // parent::beforeTraverse($nodes);
68-
69- if ($ this ->shouldSkipNodes ($ node ->stmts , $ this ->file )) {
66+ // shebang files cannot have declare strict types
67+ if ($ this ->file ->hasShebang ()) {
7068 return null ;
7169 }
7270
73- // /** @var Node $rootStmt */
74- // $rootStmt = current();
71+ // only add to namespaced files, as global namespace files are often included in other files
7572 if (! $ node ->isNamespaced ()) {
7673 return null ;
7774 }
@@ -82,13 +79,10 @@ public function refactor(Node $node): ?FileNode
8279 return null ;
8380 }
8481
85- // $rectorWithLineChange = new RectorWithLineChange(self::class, $rootStmt->getStartLine());
86- // $this->file->addRectorClassWithLine($rectorWithLineChange);
87-
88- $ node ->stmts = array_merge ([$ this ->nodeFactory ->createDeclaresStrictType (), new Nop ()], $ node ->stmts );
82+ $ declaresStrictType = $ this ->nodeFactory ->createDeclaresStrictType ();
83+ $ node ->stmts = array_merge ([$ declaresStrictType , new Nop ()], $ node ->stmts );
8984
9085 return $ node ;
91- // return [$this->nodeFactory->createDeclaresStrictType(), new Nop(), ...$nodes];
9286 }
9387
9488 /**
@@ -103,21 +97,4 @@ public function provideMinPhpVersion(): int
10397 {
10498 return PhpVersion::PHP_70 ;
10599 }
106-
107- /**
108- * @param Stmt[] $nodes
109- */
110- private function shouldSkipNodes (array $ nodes , File $ file ): bool
111- {
112- if ($ this ->skipper ->shouldSkipElementAndFilePath (self ::class, $ file ->getFilePath ())) {
113- return true ;
114- }
115-
116- // shebang files cannot have declare strict types
117- if (str_starts_with ($ file ->getFileContent (), '#! ' )) {
118- return true ;
119- }
120-
121- return $ nodes === [];
122- }
123100}
0 commit comments