Skip to content

Commit

Permalink
NarrowUnionTypeDocRector should skip literal strings (#763)
Browse files Browse the repository at this point in the history
  • Loading branch information
devbanana committed Aug 26, 2021
1 parent 47ad54d commit d8a6725
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PHPStan\Type\ArrayType;
use PHPStan\Type\BooleanType;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\FloatType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\IterableType;
Expand Down Expand Up @@ -102,7 +103,7 @@ public function isScalar(UnionType $unionType): bool
}

foreach ($types as $type) {
if ($type instanceof StringType) {
if ($type instanceof StringType && !$type instanceof ConstantStringType) {
continue;
}
if ($type instanceof FloatType) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\ClassMethod\NarrowUnionTypeDocRector\Fixture;

class SkipConstantUnion
{
public const A = 'a';
public const B = 'b';
public const C = 'c';
public const D = 'd';

/**
* @param self::* $value
*/
public function run(string $value): void
{
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\ClassMethod\NarrowUnionTypeDocRector\Fixture;

class SkipLiteralUnion
{
/**
* @param 'a'|'b'|'c'|'d' $value
*/
public function run(string $value): void
{
}
}

?>

0 comments on commit d8a6725

Please sign in to comment.