Skip to content

Commit

Permalink
Updated Rector to commit 0c035c3
Browse files Browse the repository at this point in the history
rectorphp/rector-src@5689cbe remove passing extra fileInfo with file, already included rectorphp/rector-src@7bba40a remove OPTION_ prefix rectorphp/rector-src@c2ce610 remove extra parma in value object rectorphp/rector-src@77a90c5 remove is cache debug rectorphp/rector-src@ff3de64 add shot options constant rectorphp/rector-src@0c035c3 misc
  • Loading branch information
TomasVotruba committed Jun 22, 2021
1 parent b5f061b commit 98ca095
Show file tree
Hide file tree
Showing 21 changed files with 79 additions and 95 deletions.
2 changes: 1 addition & 1 deletion config/set/downgrade-php80.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// @see https://wiki.php.net/rfc/stringable
'Stringable',
]]]);
$services->set(\Rector\DowngradePhp80\Rector\Class_\DowngradeAttributeToAnnotationRector::class)->call('configure', [[\Rector\DowngradePhp80\Rector\Class_\DowngradeAttributeToAnnotationRector::ATTRIBUTE_TO_ANNOTATION => \Symplify\SymfonyPhpConfig\ValueObjectInliner::inline([new \Rector\DowngradePhp80\ValueObject\DowngradeAttributeToAnnotation('Attribute', 'Attribute')])]]);
$services->set(\Rector\DowngradePhp80\Rector\Class_\DowngradeAttributeToAnnotationRector::class)->call('configure', [[\Rector\DowngradePhp80\Rector\Class_\DowngradeAttributeToAnnotationRector::ATTRIBUTE_TO_ANNOTATION => \Symplify\SymfonyPhpConfig\ValueObjectInliner::inline([new \Rector\DowngradePhp80\ValueObject\DowngradeAttributeToAnnotation('Attribute')])]]);
$services->set(\Rector\DowngradePhp80\Rector\Property\DowngradeUnionTypeTypedPropertyRector::class);
$services->set(\Rector\DowngradePhp80\Rector\FunctionLike\DowngradeUnionTypeDeclarationRector::class);
$services->set(\Rector\DowngradePhp80\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector::class);
Expand Down
2 changes: 1 addition & 1 deletion packages/FileSystemRector/Parser/FileInfoParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public function parseFileInfoToNodesAndDecorate(\Symplify\SmartFileSystem\SmartF
{
$oldStmts = $this->parser->parseFileInfo($smartFileInfo);
$file = new \Rector\Core\ValueObject\Application\File($smartFileInfo, $smartFileInfo->getContents());
return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($file, $oldStmts, $smartFileInfo);
return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($file, $oldStmts);
}
}
5 changes: 3 additions & 2 deletions packages/NodeTypeResolver/NodeScopeAndMetadataDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Rector\NodeTypeResolver\NodeVisitor\NamespaceNodeVisitor;
use Rector\NodeTypeResolver\NodeVisitor\StatementNodeVisitor;
use Rector\NodeTypeResolver\PHPStan\Scope\PHPStanNodeScopeResolver;
use Symplify\SmartFileSystem\SmartFileInfo;
final class NodeScopeAndMetadataDecorator
{
/**
Expand Down Expand Up @@ -66,15 +65,17 @@ public function __construct(\PhpParser\NodeVisitor\CloningVisitor $cloningVisito
* @param Stmt[] $nodes
* @return Stmt[]
*/
public function decorateNodesFromFile(\Rector\Core\ValueObject\Application\File $file, array $nodes, \Symplify\SmartFileSystem\SmartFileInfo $smartFileInfo) : array
public function decorateNodesFromFile(\Rector\Core\ValueObject\Application\File $file, array $nodes) : array
{
$nodeTraverser = new \PhpParser\NodeTraverser();
$nodeTraverser->addVisitor(new \PhpParser\NodeVisitor\NameResolver(null, [
'preserveOriginalNames' => \true,
// required by PHPStan
'replaceNodes' => \true,
]));
/** @var Stmt[] $nodes */
$nodes = $nodeTraverser->traverse($nodes);
$smartFileInfo = $file->getSmartFileInfo();
$nodes = $this->phpStanNodeScopeResolver->processNodes($nodes, $smartFileInfo);
$nodeTraverser = new \PhpParser\NodeTraverser();
$preservingNameResolver = new \PhpParser\NodeVisitor\NameResolver(null, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ private function reportCacheDebugAndSaveDependentFiles(\Symplify\SmartFileSystem
if (!$this->configuration->isCacheEnabled()) {
return;
}
$this->reportCacheDebug($smartFileInfo, $dependentFiles);
// save for cache
$this->changedFilesDetector->addFileWithDependencies($smartFileInfo, $dependentFiles);
}
Expand All @@ -195,18 +194,4 @@ private function resolveClassName($classLike) : string
}
return $classLike->name->toString();
}
/**
* @param string[] $dependentFiles
*/
private function reportCacheDebug(\Symplify\SmartFileSystem\SmartFileInfo $smartFileInfo, array $dependentFiles) : void
{
if (!$this->configuration->isCacheDebug()) {
return;
}
$message = \sprintf('[debug] %d dependencies for "%s" file', \count($dependentFiles), $smartFileInfo->getRealPath());
$this->symfonyStyle->note($message);
if ($dependentFiles !== []) {
$this->symfonyStyle->listing($dependentFiles);
}
}
}
2 changes: 1 addition & 1 deletion packages/Testing/TestingParser/TestingParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function parseFileToDecoratedNodes(string $file) : array
$this->parameterProvider->changeParameter(\Rector\Core\Configuration\Option::SOURCE, [$file]);
$nodes = $this->parser->parseFileInfo($smartFileInfo);
$file = new \Rector\Core\ValueObject\Application\File($smartFileInfo, $smartFileInfo->getContents());
return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($file, $nodes, $smartFileInfo);
return $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($file, $nodes);
}
/**
* @template T of Node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function action()
}
}
CODE_SAMPLE
, [self::ATTRIBUTE_TO_ANNOTATION => [new \Rector\DowngradePhp80\ValueObject\DowngradeAttributeToAnnotation('Symfony\\Component\\Routing\\Annotation\\Route', 'Symfony\\Component\\Routing\\Annotation\\Route')]])]);
, [self::ATTRIBUTE_TO_ANNOTATION => [new \Rector\DowngradePhp80\ValueObject\DowngradeAttributeToAnnotation('Symfony\\Component\\Routing\\Annotation\\Route')]])]);
}
/**
* @return array<class-string<Node>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ final class DowngradeAttributeToAnnotation
*/
private $attributeClass;
/**
* @var string
* @var string|null
*/
private $tag;
/**
* @param class-string $attributeClass
* @param class-string|string $tag
* @param class-string|string|null $tag
*/
public function __construct(string $attributeClass, string $tag)
public function __construct(string $attributeClass, ?string $tag = null)
{
$this->attributeClass = $attributeClass;
$this->tag = $tag;
Expand All @@ -28,6 +28,9 @@ public function getAttributeClass() : string
}
public function getTag() : string
{
if ($this->tag === null) {
return $this->attributeClass;
}
return $this->tag;
}
}
2 changes: 1 addition & 1 deletion src/Application/FileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function parseFileInfoToLocalCache(\Rector\Core\ValueObject\Application\F
$smartFileInfo = $file->getSmartFileInfo();
$oldStmts = $this->parser->parseFileInfo($smartFileInfo);
$oldTokens = $this->lexer->getTokens();
$newStmts = $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($file, $oldStmts, $smartFileInfo);
$newStmts = $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($file, $oldStmts);
$file->hydrateStmtsAndTokens($newStmts, $oldStmts, $oldTokens);
}
public function refactor(\Rector\Core\ValueObject\Application\File $file) : void
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '28891ea62d7ee55dd7a247668b43aa10e6aec4ae';
public const PACKAGE_VERSION = '0c035c390d4afd73b76f186313d4b7f7d906e072';
/**
* @var string
*/
public const RELEASE_DATE = '2021-06-22 17:24:53';
public const RELEASE_DATE = '2021-06-22 17:45:36';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20210622\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
Expand Down
7 changes: 2 additions & 5 deletions src/Autoloading/AdditionalAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public function __construct(\RectorPrefix20210622\Symplify\SmartFileSystem\FileS
}
public function autoloadInput(\RectorPrefix20210622\Symfony\Component\Console\Input\InputInterface $input) : void
{
if (!$input->hasOption(\Rector\Core\Configuration\Option::OPTION_AUTOLOAD_FILE)) {
if (!$input->hasOption(\Rector\Core\Configuration\Option::AUTOLOAD_FILE)) {
return;
}
/** @var string|null $autoloadFile */
$autoloadFile = $input->getOption(\Rector\Core\Configuration\Option::OPTION_AUTOLOAD_FILE);
$autoloadFile = $input->getOption(\Rector\Core\Configuration\Option::AUTOLOAD_FILE);
if ($autoloadFile === null) {
return;
}
Expand All @@ -47,9 +47,6 @@ public function autoloadInput(\RectorPrefix20210622\Symfony\Component\Console\In
public function autoloadPaths() : void
{
$autoloadPaths = $this->parameterProvider->provideArrayParameter(\Rector\Core\Configuration\Option::AUTOLOAD_PATHS);
if ($autoloadPaths === []) {
return;
}
$this->dynamicSourceLocatorDecorator->addPaths($autoloadPaths);
}
}
24 changes: 6 additions & 18 deletions src/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ final class Configuration
* @var string
*/
private $outputFormat;
/**
* @var bool
*/
private $isCacheDebug = \false;
/**
* @var bool
*/
Expand Down Expand Up @@ -67,12 +63,11 @@ public function __construct(\RectorPrefix20210622\Symplify\PackageBuilder\Parame
*/
public function resolveFromInput(\RectorPrefix20210622\Symfony\Component\Console\Input\InputInterface $input) : void
{
$this->isDryRun = (bool) $input->getOption(\Rector\Core\Configuration\Option::OPTION_DRY_RUN);
$this->shouldClearCache = (bool) $input->getOption(\Rector\Core\Configuration\Option::OPTION_CLEAR_CACHE);
$this->isDryRun = (bool) $input->getOption(\Rector\Core\Configuration\Option::DRY_RUN);
$this->shouldClearCache = (bool) $input->getOption(\Rector\Core\Configuration\Option::CLEAR_CACHE);
$this->showProgressBar = $this->canShowProgressBar($input);
$this->showDiffs = !(bool) $input->getOption(\Rector\Core\Configuration\Option::OPTION_NO_DIFFS);
$this->isCacheDebug = (bool) $input->getOption(\Rector\Core\Configuration\Option::CACHE_DEBUG);
$this->outputFormat = (string) $input->getOption(\Rector\Core\Configuration\Option::OPTION_OUTPUT_FORMAT);
$this->showDiffs = !(bool) $input->getOption(\Rector\Core\Configuration\Option::NO_DIFFS);
$this->outputFormat = (string) $input->getOption(\Rector\Core\Configuration\Option::OUTPUT_FORMAT);
$commandLinePaths = (array) $input->getArgument(\Rector\Core\Configuration\Option::SOURCE);
// manual command line value has priority
if ($commandLinePaths !== []) {
Expand All @@ -93,19 +88,12 @@ public function isDryRun() : bool
}
public function shouldShowProgressBar() : bool
{
if ($this->isCacheDebug) {
return \false;
}
return $this->showProgressBar;
}
public function shouldClearCache() : bool
{
return $this->shouldClearCache;
}
public function isCacheDebug() : bool
{
return $this->isCacheDebug;
}
public function isCacheEnabled() : bool
{
return $this->isCacheEnabled;
Expand Down Expand Up @@ -165,11 +153,11 @@ public function getMainConfigFilePath() : ?string
}
private function canShowProgressBar(\RectorPrefix20210622\Symfony\Component\Console\Input\InputInterface $input) : bool
{
$noProgressBar = (bool) $input->getOption(\Rector\Core\Configuration\Option::OPTION_NO_PROGRESS_BAR);
$noProgressBar = (bool) $input->getOption(\Rector\Core\Configuration\Option::NO_PROGRESS_BAR);
if ($noProgressBar) {
return \false;
}
$optionOutputFormat = $input->getOption(\Rector\Core\Configuration\Option::OPTION_OUTPUT_FORMAT);
$optionOutputFormat = $input->getOption(\Rector\Core\Configuration\Option::OUTPUT_FORMAT);
return $optionOutputFormat === \Rector\ChangesReporting\Output\ConsoleOutputFormatter::NAME;
}
/**
Expand Down
32 changes: 20 additions & 12 deletions src/Configuration/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,27 @@ final class Option
/**
* @var string
*/
public const OPTION_AUTOLOAD_FILE = 'autoload-file';
public const AUTOLOAD_FILE = 'autoload-file';
/**
* @var string
*/
public const BOOTSTRAP_FILES = 'bootstrap_files';
/**
* @var string
*/
public const OPTION_DRY_RUN = 'dry-run';
public const DRY_RUN = 'dry-run';
/**
* @var string
*/
public const OPTION_OUTPUT_FORMAT = 'output-format';
public const DRY_RUN_SHORT = 'n';
/**
* @var string
*/
public const OPTION_NO_PROGRESS_BAR = 'no-progress-bar';
public const OUTPUT_FORMAT = 'output-format';
/**
* @var string
*/
public const NO_PROGRESS_BAR = 'no-progress-bar';
/**
* @var string
*/
Expand All @@ -53,15 +57,11 @@ final class Option
/**
* @var string
*/
public const OPTION_CLEAR_CACHE = 'clear-cache';
public const CLEAR_CACHE = 'clear-cache';
/**
* @var string
*/
public const ENABLE_CACHE = 'enable_cache';
/**
* @var string
*/
public const CACHE_DEBUG = 'cache-debug';
/**
* @var string
*/
Expand Down Expand Up @@ -89,15 +89,15 @@ final class Option
/**
* @var string
*/
public const OPTION_DEBUG = 'debug';
public const DEBUG = 'debug';
/**
* @var string
*/
public const XDEBUG = 'xdebug';
/**
* @var string
*/
public const OPTION_CONFIG = 'config';
public const CONFIG = 'config';
/**
* @var string
*/
Expand All @@ -109,7 +109,7 @@ final class Option
/**
* @var string
*/
public const OPTION_NO_DIFFS = 'no-diffs';
public const NO_DIFFS = 'no-diffs';
/**
* @var string
*/
Expand All @@ -118,4 +118,12 @@ final class Option
* @var string
*/
public const ENABLE_EDITORCONFIG = 'enable_editorconfig';
/**
* @var string
*/
public const AUTOLOAD_FILE_SHORT = 'a';
/**
* @var string
*/
public const OUTPUT_FORMAT_SHORT = 'o';
}
19 changes: 9 additions & 10 deletions src/Console/Command/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,14 @@ protected function configure() : void
{
$this->setDescription('Upgrade or refactor source code with provided rectors');
$this->addArgument(\Rector\Core\Configuration\Option::SOURCE, \RectorPrefix20210622\Symfony\Component\Console\Input\InputArgument::OPTIONAL | \RectorPrefix20210622\Symfony\Component\Console\Input\InputArgument::IS_ARRAY, 'Files or directories to be upgraded.');
$this->addOption(\Rector\Core\Configuration\Option::OPTION_DRY_RUN, 'n', \RectorPrefix20210622\Symfony\Component\Console\Input\InputOption::VALUE_NONE, 'See diff of changes, do not save them to files.');
$this->addOption(\Rector\Core\Configuration\Option::OPTION_AUTOLOAD_FILE, 'a', \RectorPrefix20210622\Symfony\Component\Console\Input\InputOption::VALUE_REQUIRED, 'File with extra autoload');
$this->addOption(\Rector\Core\Configuration\Option::DRY_RUN, \Rector\Core\Configuration\Option::DRY_RUN_SHORT, \RectorPrefix20210622\Symfony\Component\Console\Input\InputOption::VALUE_NONE, 'See diff of changes, do not save them to files.');
$this->addOption(\Rector\Core\Configuration\Option::AUTOLOAD_FILE, \Rector\Core\Configuration\Option::AUTOLOAD_FILE_SHORT, \RectorPrefix20210622\Symfony\Component\Console\Input\InputOption::VALUE_REQUIRED, 'File with extra autoload');
$names = $this->outputFormatterCollector->getNames();
$description = \sprintf('Select output format: "%s".', \implode('", "', $names));
$this->addOption(\Rector\Core\Configuration\Option::OPTION_OUTPUT_FORMAT, 'o', \RectorPrefix20210622\Symfony\Component\Console\Input\InputOption::VALUE_OPTIONAL, $description, \Rector\ChangesReporting\Output\ConsoleOutputFormatter::NAME);
$this->addOption(\Rector\Core\Configuration\Option::OPTION_NO_PROGRESS_BAR, null, \RectorPrefix20210622\Symfony\Component\Console\Input\InputOption::VALUE_NONE, 'Hide progress bar. Useful e.g. for nicer CI output.');
$this->addOption(\Rector\Core\Configuration\Option::OPTION_NO_DIFFS, null, \RectorPrefix20210622\Symfony\Component\Console\Input\InputOption::VALUE_NONE, 'Hide diffs of changed files. Useful e.g. for nicer CI output.');
$this->addOption(\Rector\Core\Configuration\Option::CACHE_DEBUG, null, \RectorPrefix20210622\Symfony\Component\Console\Input\InputOption::VALUE_NONE, 'Debug changed file cache');
$this->addOption(\Rector\Core\Configuration\Option::OPTION_CLEAR_CACHE, null, \RectorPrefix20210622\Symfony\Component\Console\Input\InputOption::VALUE_NONE, 'Clear unchaged files cache');
$this->addOption(\Rector\Core\Configuration\Option::OUTPUT_FORMAT, \Rector\Core\Configuration\Option::OUTPUT_FORMAT_SHORT, \RectorPrefix20210622\Symfony\Component\Console\Input\InputOption::VALUE_OPTIONAL, $description, \Rector\ChangesReporting\Output\ConsoleOutputFormatter::NAME);
$this->addOption(\Rector\Core\Configuration\Option::NO_PROGRESS_BAR, null, \RectorPrefix20210622\Symfony\Component\Console\Input\InputOption::VALUE_NONE, 'Hide progress bar. Useful e.g. for nicer CI output.');
$this->addOption(\Rector\Core\Configuration\Option::NO_DIFFS, null, \RectorPrefix20210622\Symfony\Component\Console\Input\InputOption::VALUE_NONE, 'Hide diffs of changed files. Useful e.g. for nicer CI output.');
$this->addOption(\Rector\Core\Configuration\Option::CLEAR_CACHE, null, \RectorPrefix20210622\Symfony\Component\Console\Input\InputOption::VALUE_NONE, 'Clear unchaged files cache');
}
protected function execute(\RectorPrefix20210622\Symfony\Component\Console\Input\InputInterface $input, \RectorPrefix20210622\Symfony\Component\Console\Output\OutputInterface $output) : int
{
Expand All @@ -121,7 +120,7 @@ protected function execute(\RectorPrefix20210622\Symfony\Component\Console\Input
$this->configurePHPStanNodeScopeResolver($files);
$this->applicationFileProcessor->run($files);
// report diffs and errors
$outputFormat = (string) $input->getOption(\Rector\Core\Configuration\Option::OPTION_OUTPUT_FORMAT);
$outputFormat = (string) $input->getOption(\Rector\Core\Configuration\Option::OUTPUT_FORMAT);
$outputFormatter = $this->outputFormatterCollector->getByName($outputFormat);
// here should be value obect factory
$processResult = $this->processResultFactory->create($files);
Expand All @@ -136,15 +135,15 @@ protected function initialize(\RectorPrefix20210622\Symfony\Component\Console\In
if (!$application instanceof \RectorPrefix20210622\Symfony\Component\Console\Application) {
throw new \Rector\Core\Exception\ShouldNotHappenException();
}
$optionDebug = (bool) $input->getOption(\Rector\Core\Configuration\Option::OPTION_DEBUG);
$optionDebug = (bool) $input->getOption(\Rector\Core\Configuration\Option::DEBUG);
if ($optionDebug) {
$application->setCatchExceptions(\false);
// clear cache
$this->changedFilesDetector->clear();
return;
}
// clear cache
$optionClearCache = (bool) $input->getOption(\Rector\Core\Configuration\Option::OPTION_CLEAR_CACHE);
$optionClearCache = (bool) $input->getOption(\Rector\Core\Configuration\Option::CLEAR_CACHE);
if ($optionClearCache) {
$this->changedFilesDetector->clear();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/ShowCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ protected function configure() : void
$this->setDescription('Show loaded Rectors with their configuration');
$names = $this->showOutputFormatterCollector->getNames();
$description = \sprintf('Select output format: "%s".', \implode('", "', $names));
$this->addOption(\Rector\Core\Configuration\Option::OPTION_OUTPUT_FORMAT, 'o', \RectorPrefix20210622\Symfony\Component\Console\Input\InputOption::VALUE_OPTIONAL, $description, \Rector\ChangesReporting\Output\ConsoleOutputFormatter::NAME);
$this->addOption(\Rector\Core\Configuration\Option::OUTPUT_FORMAT, 'o', \RectorPrefix20210622\Symfony\Component\Console\Input\InputOption::VALUE_OPTIONAL, $description, \Rector\ChangesReporting\Output\ConsoleOutputFormatter::NAME);
}
protected function execute(\RectorPrefix20210622\Symfony\Component\Console\Input\InputInterface $input, \RectorPrefix20210622\Symfony\Component\Console\Output\OutputInterface $output) : int
{
$outputFormat = (string) $input->getOption(\Rector\Core\Configuration\Option::OPTION_OUTPUT_FORMAT);
$outputFormat = (string) $input->getOption(\Rector\Core\Configuration\Option::OUTPUT_FORMAT);
$this->reportLoadedRectors($outputFormat);
return \RectorPrefix20210622\Symplify\PackageBuilder\Console\ShellCode::SUCCESS;
}
Expand Down
Loading

0 comments on commit 98ca095

Please sign in to comment.