Skip to content

Commit

Permalink
[Core] Replace deprecated ShellCode:: with Symfony Command:: for stat…
Browse files Browse the repository at this point in the history
…us (#737)

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
samsonasik and actions-user committed Aug 22, 2021
1 parent 974d5ee commit b422a9d
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 35 deletions.
7 changes: 4 additions & 3 deletions bin/rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
use Rector\Core\Console\Style\SymfonyStyleFactory;
use Rector\Core\DependencyInjection\RectorContainerFactory;
use Rector\Core\HttpKernel\RectorKernel;
use Symplify\PackageBuilder\Console\ShellCode;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArgvInput;
use Symplify\PackageBuilder\Reflection\PrivatesCaller;

// @ intentionally: continue anyway
Expand Down Expand Up @@ -57,7 +58,7 @@
$container = $rectorContainerFactory->createFromBootstrapConfigs($bootstrapConfigs);
} catch (Throwable $throwable) {
// for json output
$argvInput = new \Symfony\Component\Console\Input\ArgvInput();
$argvInput = new ArgvInput();
$outputFormat = $argvInput->getParameterOption('--' . Option::OUTPUT_FORMAT);

// report fatal error in json format
Expand All @@ -72,7 +73,7 @@
$symfonyStyle->error($throwable->getMessage());
}

exit(ShellCode::ERROR);
exit(Command::FAILURE);
}

/** @var ConsoleApplication $application */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ private function refactorMethodCalls(
Param $param,
ClassMethod $classMethod,
array $methodsReturningClassInstance
): void
{
): void {
if ($classMethod->stmts === null) {
return;
}
Expand All @@ -126,8 +125,7 @@ private function refactorMethodCall(
Param $param,
MethodCall $methodCall,
array $methodsReturningClassInstance
): void
{
): void {
$paramName = $this->nodeNameResolver->getName($param->var);
if ($paramName === null) {
return;
Expand Down Expand Up @@ -159,8 +157,7 @@ private function shouldSkipMethodCallRefactor(
string $paramName,
MethodCall $methodCall,
array $methodsReturningClassInstance
): bool
{
): bool {
if (! $this->nodeNameResolver->isName($methodCall->var, $paramName)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,22 @@ private function shouldSkip(Foreach_ $foreach): bool
return true;
}

/** @var Scope $scope */
$scope = $foreach->expr->getAttribute(AttributeKey::SCOPE);

if (! $scope instanceof Scope) {
return false;
return true;
}

$type = $scope->getType($foreach->expr);

if ($type instanceof ObjectType) {
return $type->isIterable()->yes();
return $type->isIterable()
->yes();
}

if ($type instanceof ThisType) {
return $type->isIterable()->yes();
return $type->isIterable()
->yes();
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ private function getDifferentParamTypeFromAncestorClass(Param $param, FunctionLi
private function resolveParentReflectionMethod(
ClassReflection $classReflection,
string $methodName
): ?ReflectionMethod
{
): ?ReflectionMethod {
if (! $classReflection->hasMethod($methodName)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ public function getStatic()
*/
public function refactor(Node $node): ?Node
{
if ($node->returnType instanceof Name && $this->nodeNameResolver->isName(
$node->returnType,
'self'
)) {
if ($node->returnType instanceof Name && $this->nodeNameResolver->isName($node->returnType, 'self')) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ private function hasConflictingParamType(Param $param, Type $propertyType): bool
}

// different types, not a good to fit
return ! $isAllFullyQualifiedObjectType && ! $this->typeComparator->areTypesEqual($propertyType, $matchedParamType);
return ! $isAllFullyQualifiedObjectType && ! $this->typeComparator->areTypesEqual(
$propertyType,
$matchedParamType
);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use DateTime;
use Rector\Core\Exception\VersionException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Process\Process;
use Symplify\PackageBuilder\Console\ShellCode;

/**
* Inspired by https://github.com/composer/composer/blob/master/src/Composer/Composer.php
Expand All @@ -28,7 +28,7 @@ final class VersionResolver
public static function resolvePackageVersion(): string
{
$process = new Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
if ($process->run() !== ShellCode::SUCCESS) {
if ($process->run() !== Command::SUCCESS) {
throw new VersionException(
'You must ensure to run compile from composer git repository clone and that git binary is available.'
);
Expand All @@ -41,7 +41,7 @@ public static function resolvePackageVersion(): string
public static function resolverReleaseDateTime(): DateTime
{
$process = new Process(['git', 'log', '-n1', '--pretty=%ci', 'HEAD'], __DIR__);
if ($process->run() !== ShellCode::SUCCESS) {
if ($process->run() !== Command::SUCCESS) {
throw new VersionException(
'You must ensure to run compile from composer git repository clone and that git binary is available.'
);
Expand Down
3 changes: 1 addition & 2 deletions src/Console/Command/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symplify\PackageBuilder\Console\ShellCode;
use Symplify\SmartFileSystem\FileSystemGuard;
use Symplify\SmartFileSystem\SmartFileSystem;

Expand Down Expand Up @@ -63,7 +62,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->symfonyStyle->success('"rector.php" config file was added');
}

return ShellCode::SUCCESS;
return Command::SUCCESS;
}

private function resolveTemplateFilePathByType(string $templateType): string
Expand Down
7 changes: 3 additions & 4 deletions src/Console/Command/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symplify\PackageBuilder\Console\ShellCode;

final class ProcessCommand extends Command
{
Expand Down Expand Up @@ -185,15 +184,15 @@ private function resolveReturnCode(ProcessResult $processResult, Configuration $
{
// some errors were found → fail
if ($processResult->getErrors() !== []) {
return ShellCode::ERROR;
return Command::FAILURE;
}

// inverse error code for CI dry-run
if (! $configuration->isDryRun()) {
return ShellCode::SUCCESS;
return Command::SUCCESS;
}

return $processResult->getFileDiffs() === [] ? ShellCode::SUCCESS : ShellCode::ERROR;
return $processResult->getFileDiffs() === [] ? Command::SUCCESS : Command::FAILURE;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Console/Command/ShowCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symplify\PackageBuilder\Console\ShellCode;

final class ShowCommand extends Command
{
Expand Down Expand Up @@ -52,7 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->reportLoadedRectors($outputFormat);

return ShellCode::SUCCESS;
return Command::SUCCESS;
}

private function reportLoadedRectors(string $outputFormat): void
Expand Down
4 changes: 2 additions & 2 deletions src/Reporting/MissingRectorRulesReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Rector\Core\Contract\Rector\RectorInterface;
use Rector\PostRector\Contract\Rector\ComplementaryRectorInterface;
use Rector\PostRector\Contract\Rector\PostRectorInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symplify\PackageBuilder\Console\ShellCode;

final class MissingRectorRulesReporter
{
Expand Down Expand Up @@ -40,7 +40,7 @@ function (RectorInterface $rector): bool {

$this->report();

return ShellCode::ERROR;
return Command::FAILURE;
}

public function report(): void
Expand Down
3 changes: 1 addition & 2 deletions utils/compiler/src/Command/DowngradePathsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;
use Symplify\PackageBuilder\Console\ShellCode;

final class DowngradePathsCommand extends Command
{
Expand Down Expand Up @@ -76,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$downgradePathsLine = implode(';', $downgradePaths);
echo $downgradePathsLine . PHP_EOL;

return ShellCode::SUCCESS;
return Command::SUCCESS;
}

/**
Expand Down

0 comments on commit b422a9d

Please sign in to comment.