Fixes #4013 ConsoleExecuteReturnIntRector ignores already type casted variable (#4095)

* #4013: Don't force type hint if already forced.

* Fixes #4013 ConsoleExecuteReturnIntRector ignores already type casted variable

Signed-off-by: Abdul Malik Ikhsan <samsonasik@gmail.com>

* remove no expected change already casted variable fixture

Signed-off-by: Abdul Malik Ikhsan <samsonasik@gmail.com>

* remove unneded $hasReturn fill on check node->expr instanceof Int_

Co-authored-by: Aerendir <hello@aerendir.me>
This commit is contained in:
Abdul Malik Ikhsan 2020-09-01 20:57:00 +07:00 committed by GitHub
parent 95bbb3063c
commit 3d2a35d63e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View File

@ -112,6 +112,10 @@ PHP
return null;
}
if ($node->expr instanceof Int_) {
return null;
}
// is there return without nesting?
if ($this->areNodesEqual($node->getAttribute(AttributeKey::PARENT_NODE), $classMethod)) {
$hasReturn = true;

View File

@ -0,0 +1,31 @@
<?php
namespace Rector\Symfony\Tests\Rector\ClassMethod\ConsoleExecuteReturnIntRector\Fixture;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
abstract class AbstractSkipAlreadyTypeHintedCommand extends Command
{
public function execute(InputInterface $input, OutputInterface $output):int
{
return 1;
}
}
final class SkipAlreadyTypeHintedCommand extends AbstractSkipAlreadyTypeHintedCommand
{
protected static $defaultName = 'shq:user:create';
public function execute(InputInterface $input, OutputInterface $output):int
{
$initialized = parent::execute($input, $output);
if (0 !== $initialized) {
return (int) $initialized;
}
return 0;
}
}