Skip to content

Commit 54d38a3

Browse files
committed
tidy up
1 parent 101192e commit 54d38a3

4 files changed

Lines changed: 25 additions & 18 deletions

File tree

src/Testing/TestingParser/TestingParser.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,7 @@ public function __construct(
2727

2828
public function parseFilePathToFile(string $filePath): File
2929
{
30-
// needed for PHPStan reflection, as it caches the last processed file
31-
$this->dynamicSourceLocatorProvider->setFilePath($filePath);
32-
33-
$fileContent = FileSystem::read($filePath);
34-
$file = new File($filePath, $fileContent);
35-
$stmts = $this->rectorParser->parseString($fileContent);
36-
37-
$stmts = $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($filePath, $stmts);
38-
39-
$file->hydrateStmtsAndTokens($stmts, $stmts, []);
40-
$this->currentFileProvider->setFile($file);
30+
[$file, $stmts] = $this->parseToFileAndStmts($filePath);
4131

4232
return $file;
4333
}
@@ -46,19 +36,29 @@ public function parseFilePathToFile(string $filePath): File
4636
* @return Node[]
4737
*/
4838
public function parseFileToDecoratedNodes(string $filePath): array
39+
{
40+
[$file, $stmts] = $this->parseToFileAndStmts($filePath);
41+
42+
return $stmts;
43+
}
44+
45+
/**
46+
* @return array{0: File, 1: Node[]}
47+
*/
48+
private function parseToFileAndStmts(string $filePath): array
4949
{
5050
// needed for PHPStan reflection, as it caches the last processed file
5151
$this->dynamicSourceLocatorProvider->setFilePath($filePath);
5252

5353
$fileContent = FileSystem::read($filePath);
54-
$stmts = $this->rectorParser->parseString($fileContent);
5554
$file = new File($filePath, $fileContent);
5655

56+
$stmts = $this->rectorParser->parseString($fileContent);
5757
$stmts = $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($filePath, $stmts);
58-
$file->hydrateStmtsAndTokens($stmts, $stmts, []);
5958

59+
$file->hydrateStmtsAndTokens($stmts, $stmts, []);
6060
$this->currentFileProvider->setFile($file);
6161

62-
return $stmts;
62+
return [$file, $stmts];
6363
}
6464
}

tests/Comments/CommentRemover/Fixture/another_comment.php.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Rector\Tests\Comments\CommentRemover\Fixture;
44

5-
$values = new class
5+
final class AnotherComment
66
{
77
public function run($value)
88
{
@@ -13,13 +13,13 @@ $values = new class
1313
return 'https://some_very_long_link.cz'; /* here too */
1414
}
1515
}
16-
};
16+
}
1717

1818
?>
1919
-----
2020
namespace Rector\Tests\Comments\CommentRemover\Fixture;
2121

22-
$values = new class
22+
final class AnotherComment
2323
{
2424
public function run($value)
2525
{
@@ -28,4 +28,4 @@ $values = new class
2828
return 'https://some_very_long_link.cz';
2929
}
3030
}
31-
};
31+
}

tests/Issues/AnnotationToAttributeRenameAutoImport/config/configured_rule.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Rector\Renaming\Rector\Name\RenameClassRector;
99

1010
return static function (RectorConfig $rectorConfig): void {
11+
/** triggers @see \Rector\NodeTypeResolver\PhpDocNodeVisitor\NameImportingPhpDocNodeVisitor */
1112
$rectorConfig->importNames();
1213

1314
$rectorConfig->ruleWithConfiguration(AnnotationToAttributeRector::class, [

tests/Issues/AutoImport/config/configured_rule.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,23 @@
1212
use Rector\Symfony\Symfony44\Rector\ClassMethod\ConsoleExecuteReturnIntRector;
1313

1414
return static function (RectorConfig $rectorConfig): void {
15+
/** enables @see \Rector\PostRector\Rector\NameImportingPostRector */
1516
$rectorConfig->importNames();
17+
1618
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
1719
'Some\Exception' => 'Some\Target\Exception',
1820
'DateTime' => 'DateTimeInterface',
1921
'Phalcon\Logger' => 'Phalcon\Logger\Logger',
2022
]);
23+
2124
$rectorConfig->rule(TernaryToNullCoalescingRector::class);
25+
2226
$rectorConfig->ruleWithConfiguration(AnnotationToAttributeRector::class, [
2327
new AnnotationToAttribute('Doctrine\ORM\Mapping\Entity'),
2428
]);
29+
2530
$rectorConfig->rules([ConsoleExecuteReturnIntRector::class, RemoveUnusedPrivatePropertyRector::class]);
31+
2632
$rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [
2733
'split' => 'explode',
2834
]);

0 commit comments

Comments
 (0)