Skip to content

Commit 24cd533

Browse files
[TypeDeclaration] Handle string&string intersection on AddMethodCallBasedStrictParamTypeRector (#1375)
Co-authored-by: Tomas Votruba <tomas.vot@gmail.com>
1 parent 1ba58dd commit 24cd533

4 files changed

Lines changed: 88 additions & 1 deletion

File tree

packages/NodeTypeResolver/NodeTypeResolver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ public function getNativeType(Expr $expr): Type
224224
return new MixedType();
225225
}
226226

227-
return $scope->getNativeType($expr);
227+
$type = $scope->getNativeType($expr);
228+
return $this->accessoryNonEmptyStringTypeCorrector->correct($type);
228229
}
229230

230231
public function isNumberType(Node $node): bool
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector\FixtureIntersection;
4+
5+
final class StringIntersection
6+
{
7+
public function execute()
8+
{
9+
$value = sys_get_temp_dir() . DIRECTORY_SEPARATOR . basename(__FILE__);
10+
$this->run($value);
11+
}
12+
13+
private function run($value)
14+
{
15+
}
16+
}
17+
18+
?>
19+
-----
20+
<?php
21+
22+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector\FixtureIntersection;
23+
24+
final class StringIntersection
25+
{
26+
public function execute()
27+
{
28+
$value = sys_get_temp_dir() . DIRECTORY_SEPARATOR . basename(__FILE__);
29+
$this->run($value);
30+
}
31+
32+
private function run(string $value)
33+
{
34+
}
35+
}
36+
37+
?>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector;
6+
7+
use Iterator;
8+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
9+
use Symplify\SmartFileSystem\SmartFileInfo;
10+
11+
final class IntersectionTest extends AbstractRectorTestCase
12+
{
13+
/**
14+
* @dataProvider provideData()
15+
*/
16+
public function test(SmartFileInfo $fileInfo): void
17+
{
18+
$this->doTestFileInfo($fileInfo);
19+
}
20+
21+
/**
22+
* @return Iterator<SmartFileInfo>
23+
*/
24+
public function provideData(): Iterator
25+
{
26+
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureIntersection');
27+
}
28+
29+
public function provideConfigFilePath(): string
30+
{
31+
return __DIR__ . '/config/intersection_config.php';
32+
}
33+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Core\Configuration\Option;
6+
use Rector\Core\ValueObject\PhpVersionFeature;
7+
use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector;
8+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
9+
10+
return static function (ContainerConfigurator $containerConfigurator): void {
11+
$parameters = $containerConfigurator->parameters();
12+
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::INTERSECTION_TYPES);
13+
14+
$services = $containerConfigurator->services();
15+
$services->set(AddMethodCallBasedStrictParamTypeRector::class);
16+
};

0 commit comments

Comments
 (0)