diff --git a/bin/add-phpstan-self-replace.php b/bin/add-phpstan-self-replace.php index e65922b0427..6fffe031f0e 100644 --- a/bin/add-phpstan-self-replace.php +++ b/bin/add-phpstan-self-replace.php @@ -15,6 +15,6 @@ $composerJson['replace']['phpstan/phpstan'] = $composerJson['require']['phpstan/phpstan']; $modifiedComposerJsonFileContents = Json::encode($composerJson, Json::PRETTY); -FileSystem::write(__DIR__ . '/../composer.json', $modifiedComposerJsonFileContents); +FileSystem::write(__DIR__ . '/../composer.json', $modifiedComposerJsonFileContents, null); echo 'Done!' . PHP_EOL; diff --git a/phpstan.neon b/phpstan.neon index be449492ccd..6c1ef8459ab 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -146,7 +146,7 @@ parameters: paths: - src/Caching/ValueObject/Storage/FileCacheStorage.php - - message: '#"@\\rename(.*?)" is forbidden to use#' + message: '#"@\\copy(.*?)" is forbidden to use#' paths: - src/Caching/ValueObject/Storage/FileCacheStorage.php - diff --git a/src/Caching/ValueObject/Storage/FileCacheStorage.php b/src/Caching/ValueObject/Storage/FileCacheStorage.php index ae0ee7d019c..94a4172cf8f 100644 --- a/src/Caching/ValueObject/Storage/FileCacheStorage.php +++ b/src/Caching/ValueObject/Storage/FileCacheStorage.php @@ -69,13 +69,14 @@ public function save(string $key, string $variableKey, mixed $data): void } // for performance reasons we don't use SmartFileSystem - FileSystem::write($tmpPath, \sprintf("filesystem->remove($this->directory); + FileSystem::delete($this->directory); } private function processRemoveCacheFilePath(CacheFilePaths $cacheFilePaths): void @@ -101,7 +102,7 @@ private function processRemoveCacheFilePath(CacheFilePaths $cacheFilePaths): voi return; } - $this->filesystem->remove($filePath); + FileSystem::delete($filePath); } private function processRemoveEmptyDirectory(string $directory): void @@ -114,7 +115,7 @@ private function processRemoveEmptyDirectory(string $directory): void return; } - $this->filesystem->remove($directory); + FileSystem::delete($directory); } private function isNotEmptyDirectory(string $directory): bool diff --git a/src/Configuration/ConfigInitializer.php b/src/Configuration/ConfigInitializer.php index 608895b1636..0822f0fb502 100644 --- a/src/Configuration/ConfigInitializer.php +++ b/src/Configuration/ConfigInitializer.php @@ -46,7 +46,7 @@ public function createConfig(string $projectDirectory): void $configContents = $this->replacePathsContents($configContents, $projectDirectory); - FileSystem::write($commonRectorConfigPath, $configContents); + FileSystem::write($commonRectorConfigPath, $configContents, null); $this->symfonyStyle->success('The config is added now. Re-run command to make Rector do the work!'); } diff --git a/src/Console/Command/CustomRuleCommand.php b/src/Console/Command/CustomRuleCommand.php index d6fd9f83c25..d72e753e02c 100644 --- a/src/Console/Command/CustomRuleCommand.php +++ b/src/Console/Command/CustomRuleCommand.php @@ -95,7 +95,7 @@ static function (string $answer): string { $newContent = $this->replaceNameVariable($rectorName, $fileInfo->getContents()); $newFilePath = $this->replaceNameVariable($rectorName, $fileInfo->getRelativePathname()); - FileSystem::write(getcwd() . '/' . $newFilePath, $newContent); + FileSystem::write(getcwd() . '/' . $newFilePath, $newContent, null); $generatedFilePaths[] = $newFilePath; } diff --git a/src/Console/Command/SetupCICommand.php b/src/Console/Command/SetupCICommand.php index 29ed815d541..a79d205723c 100644 --- a/src/Console/Command/SetupCICommand.php +++ b/src/Console/Command/SetupCICommand.php @@ -73,7 +73,7 @@ private function addGithubActionsWorkflow(string $currentRepository, string $tar '__CURRENT_REPOSITORY__' => $currentRepository, ]); - FileSystem::write($targetWorkflowFilePath, $workflowContents); + FileSystem::write($targetWorkflowFilePath, $workflowContents, null); $this->symfonyStyle->newLine(); $this->symfonyStyle->success('The ".github/workflows/rector.yaml" file was added'); @@ -96,7 +96,7 @@ private function addGithubActionsWorkflow(string $currentRepository, string $tar private function addGitlabFile(string $targetGitlabFilePath): void { $gitlabTemplate = FileSystem::read(__DIR__ . '/../../../templates/rector-gitlab-check.yaml'); - FileSystem::write($targetGitlabFilePath, $gitlabTemplate); + FileSystem::write($targetGitlabFilePath, $gitlabTemplate, null); $this->symfonyStyle->newLine(); $this->symfonyStyle->success('The "gitlab/rector.yaml" file was added'); diff --git a/src/FileSystem/JsonFileSystem.php b/src/FileSystem/JsonFileSystem.php index 19cb986da4a..13394743761 100644 --- a/src/FileSystem/JsonFileSystem.php +++ b/src/FileSystem/JsonFileSystem.php @@ -25,6 +25,6 @@ public static function readFilePath(string $filePath): array public static function writeFile(string $filePath, array $data): void { $json = Json::encode($data, Json::PRETTY); - FileSystem::write($filePath, $json); + FileSystem::write($filePath, $json, null); } } diff --git a/src/PhpParser/Printer/FormatPerservingPrinter.php b/src/PhpParser/Printer/FormatPerservingPrinter.php index 4166c777bd8..7053a879544 100644 --- a/src/PhpParser/Printer/FormatPerservingPrinter.php +++ b/src/PhpParser/Printer/FormatPerservingPrinter.php @@ -4,9 +4,9 @@ namespace Rector\PhpParser\Printer; +use Nette\Utils\FileSystem; use PhpParser\Node; use Rector\ValueObject\Application\File; -use Symfony\Component\Filesystem\Filesystem; /** * @see \Rector\Tests\PhpParser\Printer\FormatPerservingPrinterTest @@ -15,7 +15,6 @@ { public function __construct( private BetterStandardPrinter $betterStandardPrinter, - private Filesystem $filesystem ) { } @@ -46,6 +45,6 @@ public function printParsedStmstAndTokensToString(File $file): string public function dumpFile(string $filePath, string $newContent): void { - $this->filesystem->dumpFile($filePath, $newContent); + FileSystem::write($filePath, $newContent, null); } } diff --git a/src/Testing/Fixture/FixtureFileUpdater.php b/src/Testing/Fixture/FixtureFileUpdater.php index b846e7d54f5..b14c4d2f09a 100644 --- a/src/Testing/Fixture/FixtureFileUpdater.php +++ b/src/Testing/Fixture/FixtureFileUpdater.php @@ -22,7 +22,7 @@ public static function updateFixtureContent( $newOriginalContent = self::resolveNewFixtureContent($originalContent, $changedContent); - FileSystem::write($fixtureFilePath, $newOriginalContent); + FileSystem::write($fixtureFilePath, $newOriginalContent, null); } private static function resolveNewFixtureContent(string $originalContent, string $changedContent): string diff --git a/src/Testing/Fixture/FixtureTempFileDumper.php b/src/Testing/Fixture/FixtureTempFileDumper.php index 89d13379a90..f1de9f7eec0 100644 --- a/src/Testing/Fixture/FixtureTempFileDumper.php +++ b/src/Testing/Fixture/FixtureTempFileDumper.php @@ -22,7 +22,7 @@ public static function dump(string $fileContents, string $suffix = 'php'): strin $temporaryFileName = sys_get_temp_dir() . self::TEMP_FIXTURE_DIRECTORY . '/' . md5( $fileContents ) . '.' . $suffix; - FileSystem::write($temporaryFileName, $fileContents); + FileSystem::write($temporaryFileName, $fileContents, null); return $temporaryFileName; } diff --git a/src/Testing/PHPUnit/AbstractRectorTestCase.php b/src/Testing/PHPUnit/AbstractRectorTestCase.php index 714747c40e7..9a7310ebc9c 100644 --- a/src/Testing/PHPUnit/AbstractRectorTestCase.php +++ b/src/Testing/PHPUnit/AbstractRectorTestCase.php @@ -159,7 +159,7 @@ protected function doTestFile(string $fixtureFilePath): void } // write temp file - FileSystem::write($inputFilePath, $inputFileContents); + FileSystem::write($inputFilePath, $inputFileContents, null); $this->doTestFileMatchesExpectedContent( $inputFilePath, diff --git a/tests/Util/FileHasherTest.php b/tests/Util/FileHasherTest.php index c5e73a47a30..14586b48038 100644 --- a/tests/Util/FileHasherTest.php +++ b/tests/Util/FileHasherTest.php @@ -4,20 +4,17 @@ namespace Rector\Tests\Util; +use Nette\Utils\FileSystem; use Rector\Testing\PHPUnit\AbstractLazyTestCase; use Rector\Util\FileHasher; -use Symfony\Component\Filesystem\Filesystem; final class FileHasherTest extends AbstractLazyTestCase { private FileHasher $fileHasher; - private Filesystem $filesystem; - protected function setUp(): void { $this->fileHasher = $this->make(FileHasher::class); - $this->filesystem = $this->make(Filesystem::class); } public function testHash(): void @@ -32,12 +29,12 @@ public function testHashFiles(): void $file = $dir . '/FileHasherTest-fixture.txt'; try { - $this->filesystem->dumpFile($file, 'some string'); + FileSystem::write($file, 'some string', null); $hash = $this->fileHasher->hashFiles([$file]); $this->assertSame('8df638f91bacc826bf50c04efd7df1b1', $hash); } finally { - $this->filesystem->remove($file); + FileSystem::delete($file); } }