Skip to content

Commit 4ba1e9d

Browse files
committed
[DeadCode] Skip string scalar sub type on RemoveReturnTagIncompatibleWithNativeTypeRector
1 parent ce9583f commit 4ba1e9d

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveReturnTagIncompatibleWithNativeTypeRector\Fixture;
4+
5+
final class SkipSubtype
6+
{
7+
/**
8+
* @return callable-string
9+
*/
10+
public function getCallableString(): string
11+
{
12+
return 'trim';
13+
}
14+
15+
/**
16+
* @return non-empty-lowercase-string
17+
*/
18+
public function getNonEmptyLowercaseString(): string
19+
{
20+
return 'abc';
21+
}
22+
23+
/**
24+
* @return non-empty-uppercase-string
25+
*/
26+
public function getNonEmptyUppercaseString(): string
27+
{
28+
return 'ABC';
29+
}
30+
31+
/**
32+
* @return non-empty-literal-string
33+
*/
34+
public function getNonEmptyLiteralString(): string
35+
{
36+
return '3v4l';
37+
}
38+
39+
/**
40+
* @return decimal-int-string
41+
*/
42+
public function getDecimalIntString(): string
43+
{
44+
return '123';
45+
}
46+
47+
/**
48+
* @return non-decimal-int-string
49+
*/
50+
public function getNonDecimalIntString(): string
51+
{
52+
return '+1';
53+
}
54+
}

src/StaticTypeMapper/Mapper/ScalarStringToTypeMapper.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Nette\Utils\Strings;
88
use PHPStan\Type\Accessory\AccessoryArrayListType;
9+
use PHPStan\Type\Accessory\AccessoryDecimalIntegerStringType;
910
use PHPStan\Type\Accessory\AccessoryLiteralStringType;
1011
use PHPStan\Type\Accessory\AccessoryLowercaseStringType;
1112
use PHPStan\Type\Accessory\AccessoryNonEmptyStringType;
@@ -91,6 +92,42 @@ public function mapScalarStringToType(string $scalarName): Type
9192
return new UnionType([new IntegerType(), new StringType()]);
9293
}
9394

95+
if ($loweredScalarName === 'callable-string') {
96+
return TypeCombinator::intersect(new StringType(), new CallableType());
97+
}
98+
99+
if ($loweredScalarName === 'non-empty-lowercase-string') {
100+
return TypeCombinator::intersect(
101+
new StringType(),
102+
new AccessoryNonEmptyStringType(),
103+
new AccessoryLowercaseStringType()
104+
);
105+
}
106+
107+
if ($loweredScalarName === 'non-empty-uppercase-string') {
108+
return TypeCombinator::intersect(
109+
new StringType(),
110+
new AccessoryNonEmptyStringType(),
111+
new AccessoryUppercaseStringType()
112+
);
113+
}
114+
115+
if ($loweredScalarName === 'non-empty-literal-string') {
116+
return TypeCombinator::intersect(
117+
new StringType(),
118+
new AccessoryNonEmptyStringType(),
119+
new AccessoryLiteralStringType()
120+
);
121+
}
122+
123+
if ($loweredScalarName === 'decimal-int-string') {
124+
return TypeCombinator::intersect(new StringType(), new AccessoryDecimalIntegerStringType());
125+
}
126+
127+
if ($loweredScalarName === 'non-decimal-int-string') {
128+
return TypeCombinator::intersect(new StringType(), new AccessoryDecimalIntegerStringType(true));
129+
}
130+
94131
foreach (self::SCALAR_NAME_BY_TYPE as $objectType => $scalarNames) {
95132
if (! in_array($loweredScalarName, $scalarNames, true)) {
96133
continue;

0 commit comments

Comments
 (0)