[PHP 7.3] Register existing ContinueToBreakInSwitchRector in PHP 5.2 set to PHP 7.3 config set (#5820)

Co-authored-by: kaizen-ci <info@kaizen-ci.org>
This commit is contained in:
Abdul Malik Ikhsan 2021-03-11 17:58:11 +07:00 committed by GitHub
parent 2e3a9e7166
commit 28e1e1f3f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 52 deletions

View File

@ -2,6 +2,7 @@
declare(strict_types=1);
use Rector\Php52\Rector\Switch_\ContinueToBreakInSwitchRector;
use Rector\Php73\Rector\BooleanOr\IsCountableRector;
use Rector\Php73\Rector\ConstFetch\SensitiveConstantNameRector;
use Rector\Php73\Rector\FuncCall\ArrayKeyFirstLastRector;
@ -46,4 +47,5 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(StringifyStrNeedlesRector::class);
$services->set(JsonThrowOnErrorRector::class);
$services->set(RegexDashEscapeRector::class);
$services->set(ContinueToBreakInSwitchRector::class);
};

View File

@ -22,6 +22,9 @@ final class Php74Test extends AbstractPropertyFetchTypeResolverTest
$this->doTestFileInfo($smartFileInfo);
}
/**
* @return Iterator<mixed, SmartFileInfo>
*/
public function provideData(): Iterator
{
return StaticFixtureFinder::yieldDirectoryExclusively(__DIR__ . '/FixturePhp74');

View File

@ -22,6 +22,9 @@ final class Php80Test extends AbstractPropertyFetchTypeResolverTest
$this->doTestFileInfo($smartFileInfo);
}
/**
* @return Iterator<mixed, SmartFileInfo>
*/
public function provideData(): Iterator
{
return StaticFixtureFinder::yieldDirectoryExclusively(__DIR__ . '/FixturePhp80');

View File

@ -18,6 +18,9 @@ final class PropertyFetchTypeResolverTest extends AbstractPropertyFetchTypeResol
$this->doTestFileInfo($smartFileInfo);
}
/**
* @return Iterator<mixed, SmartFileInfo>
*/
public function provideData(): Iterator
{
return StaticFixtureFinder::yieldDirectoryExclusively(__DIR__ . '/Fixture');

View File

@ -10,6 +10,7 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode;
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
use PHPStan\Type\ArrayType;
use PHPStan\Type\Generic\GenericObjectType;
use PHPStan\Type\IterableType;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
@ -176,6 +177,13 @@ CODE_SAMPLE
return null;
}
if ($inferredReturnType instanceof GenericObjectType && $currentReturnType instanceof MixedType) {
$types = $inferredReturnType->getTypes();
if ($types[0] instanceof MixedType && $types[1] instanceof ArrayType) {
return null;
}
}
$this->phpDocTypeChanger->changeReturnType($phpDocInfo, $inferredReturnType);
$this->returnTagRemover->removeReturnTagIfUseless($phpDocInfo, $node);

View File

@ -0,0 +1,24 @@
<?php
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddArrayReturnDocTypeRector\Fixture;
use Iterator;
use Symplify\SmartFileSystem\SmartFileInfo;
final class SkipSomeIterator
{
public function someMethod(): Iterator
{
return self::someIterator();
}
/**
* @return \Iterator<array<int, SmartFileInfo>>
*/
public static function someIterator(): Iterator
{
yield [100 => new SmartFileInfo('...')];
}
}
?>

View File

@ -1,52 +0,0 @@
<?php
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddArrayReturnDocTypeRector\Fixture;
use Iterator;
use Symplify\SmartFileSystem\SmartFileInfo;
final class SomeIterator
{
public function someMethod(): Iterator
{
return self::someIterator();
}
/**
* @return \Iterator<array<int, SmartFileInfo>>
*/
public static function someIterator(): Iterator
{
yield [100 => new SmartFileInfo('...')];
}
}
?>
-----
<?php
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddArrayReturnDocTypeRector\Fixture;
use Iterator;
use Symplify\SmartFileSystem\SmartFileInfo;
final class SomeIterator
{
/**
* @return Iterator<mixed, \Symplify\SmartFileSystem\SmartFileInfo[]>
*/
public function someMethod(): Iterator
{
return self::someIterator();
}
/**
* @return \Iterator<array<int, SmartFileInfo>>
*/
public static function someIterator(): Iterator
{
yield [100 => new SmartFileInfo('...')];
}
}
?>