Skip to content

Commit

Permalink
Updated Rector to commit 1608ae8c9497bbfaf78ce54130ec304963ac6f2a
Browse files Browse the repository at this point in the history
rectorphp/rector-src@1608ae8 [Windows] Utilize Nette\Utils\FileSystem instead of Symfony\Component\Filesystem\Filesystem to write file (#5514)
  • Loading branch information
TomasVotruba committed Jan 28, 2024
1 parent 691f25c commit 94c55b8
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 27 deletions.
2 changes: 1 addition & 1 deletion bin/add-phpstan-self-replace.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
$composerJson = Json::decode($composerJsonFileContents, Json::FORCE_ARRAY);
$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;
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'e17f878d5adb301fda0de8f9da2d94d898a363c3';
public const PACKAGE_VERSION = '1608ae8c9497bbfaf78ce54130ec304963ac6f2a';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-01-29 03:51:07';
public const RELEASE_DATE = '2024-01-29 05:39:29';
/**
* @var int
*/
Expand Down
14 changes: 7 additions & 7 deletions src/Caching/ValueObject/Storage/FileCacheStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ public function save(string $key, string $variableKey, $data) : void
throw new CachingException(\sprintf('Error occurred while saving item %s (%s) to cache: %s', $key, $variableKey, $errorAfter['message']));
}
// for performance reasons we don't use SmartFileSystem
FileSystem::write($tmpPath, \sprintf("<?php declare(strict_types = 1);\n\nreturn %s;", $exported));
$renameSuccess = @\rename($tmpPath, $filePath);
if ($renameSuccess) {
FileSystem::write($tmpPath, \sprintf("<?php declare(strict_types = 1);\n\nreturn %s;", $exported), null);
$copySuccess = @\copy($tmpPath, $filePath);
@\unlink($tmpPath);
if ($copySuccess) {
return;
}
@\unlink($tmpPath);
if (\DIRECTORY_SEPARATOR === '/' || !\file_exists($filePath)) {
throw new CachingException(\sprintf('Could not write data to cache file %s.', $filePath));
}
Expand All @@ -88,15 +88,15 @@ public function clean(string $key) : void
}
public function clear() : void
{
$this->filesystem->remove($this->directory);
FileSystem::delete($this->directory);
}
private function processRemoveCacheFilePath(CacheFilePaths $cacheFilePaths) : void
{
$filePath = $cacheFilePaths->getFilePath();
if (!$this->filesystem->exists($filePath)) {
return;
}
$this->filesystem->remove($filePath);
FileSystem::delete($filePath);
}
private function processRemoveEmptyDirectory(string $directory) : void
{
Expand All @@ -106,7 +106,7 @@ private function processRemoveEmptyDirectory(string $directory) : void
if ($this->isNotEmptyDirectory($directory)) {
return;
}
$this->filesystem->remove($directory);
FileSystem::delete($directory);
}
private function isNotEmptyDirectory(string $directory) : bool
{
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/ConfigInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function createConfig(string $projectDirectory) : void
$configContents = FileSystem::read(__DIR__ . '/../../templates/rector.php.dist');
$configContents = $this->replacePhpLevelContents($configContents);
$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!');
}
public function areSomeRectorsLoaded() : bool
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/CustomRuleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
// replace __Name__ with $rectorName
$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;
}
$this->symfonyStyle->title('Generated files');
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/SetupCICommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private function addGithubActionsWorkflow(string $currentRepository, string $tar
{
$workflowTemplate = FileSystem::read(__DIR__ . '/../../../templates/rector-github-action-check.yaml');
$workflowContents = \strtr($workflowTemplate, ['__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');
$this->symfonyStyle->writeln('<comment>2 more steps to run Rector in CI:</comment>');
Expand All @@ -72,7 +72,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');
$this->symfonyStyle->newLine();
Expand Down
2 changes: 1 addition & 1 deletion src/FileSystem/JsonFileSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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);
}
}
12 changes: 3 additions & 9 deletions src/PhpParser/Printer/FormatPerservingPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
declare (strict_types=1);
namespace Rector\PhpParser\Printer;

use RectorPrefix202401\Nette\Utils\FileSystem;
use PhpParser\Node;
use Rector\ValueObject\Application\File;
use RectorPrefix202401\Symfony\Component\Filesystem\Filesystem;
/**
* @see \Rector\Tests\PhpParser\Printer\FormatPerservingPrinterTest
*/
Expand All @@ -16,15 +16,9 @@ final class FormatPerservingPrinter
* @var \Rector\PhpParser\Printer\BetterStandardPrinter
*/
private $betterStandardPrinter;
/**
* @readonly
* @var \Symfony\Component\Filesystem\Filesystem
*/
private $filesystem;
public function __construct(\Rector\PhpParser\Printer\BetterStandardPrinter $betterStandardPrinter, Filesystem $filesystem)
public function __construct(\Rector\PhpParser\Printer\BetterStandardPrinter $betterStandardPrinter)
{
$this->betterStandardPrinter = $betterStandardPrinter;
$this->filesystem = $filesystem;
}
/**
* @api tests
Expand All @@ -45,6 +39,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);
}
}
2 changes: 1 addition & 1 deletion src/Testing/Fixture/FixtureFileUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static function updateFixtureContent(string $originalContent, string $cha
return;
}
$newOriginalContent = self::resolveNewFixtureContent($originalContent, $changedContent);
FileSystem::write($fixtureFilePath, $newOriginalContent);
FileSystem::write($fixtureFilePath, $newOriginalContent, null);
}
private static function resolveNewFixtureContent(string $originalContent, string $changedContent) : string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Testing/Fixture/FixtureTempFileDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function dump(string $fileContents, string $suffix = 'php') : stri
{
// the "php" suffix is important, because that will hook into \Rector\Application\FileProcessor\PhpFileProcessor
$temporaryFileName = \sys_get_temp_dir() . self::TEMP_FIXTURE_DIRECTORY . '/' . \md5($fileContents) . '.' . $suffix;
FileSystem::write($temporaryFileName, $fileContents);
FileSystem::write($temporaryFileName, $fileContents, null);
return $temporaryFileName;
}
}
2 changes: 1 addition & 1 deletion src/Testing/PHPUnit/AbstractRectorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected function doTestFile(string $fixtureFilePath) : void
throw new ShouldNotHappenException('Fixture file and input file cannot be the same: ' . $fixtureFilePath);
}
// write temp file
FileSystem::write($inputFilePath, $inputFileContents);
FileSystem::write($inputFilePath, $inputFileContents, null);
$this->doTestFileMatchesExpectedContent($inputFilePath, $inputFileContents, $expectedFileContents, $fixtureFilePath);
}
protected function forgetRectorsRulesAndCollectors() : void
Expand Down

0 comments on commit 94c55b8

Please sign in to comment.