Skip to content

Commit b3ac267

Browse files
committed
skip narrow bool|false|<OtherTypeHere>
1 parent 3199d38 commit b3ac267

3 files changed

Lines changed: 1 addition & 36 deletions

File tree

packages/PHPStanStaticTypeMapper/TypeAnalyzer/BoolUnionTypeAnalyzer.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,6 @@ public function isBoolUnionType(UnionType $unionType): bool
2020
return true;
2121
}
2222

23-
public function hasBoolType(UnionType $unionType): bool
24-
{
25-
foreach ($unionType->getTypes() as $unionedType) {
26-
if ($unionedType->isBoolean()->yes()) {
27-
return true;
28-
}
29-
}
30-
31-
return false;
32-
}
33-
3423
public function isNullableBoolUnionType(UnionType $unionType): bool
3524
{
3625
$hasNullable = false;

packages/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,6 @@ private function narrowBoolType(
518518
return $phpParserUnionType;
519519
}
520520

521-
if ($this->boolUnionTypeAnalyzer->hasBoolType($unionType)) {
522-
return $this->phpStanStaticTypeMapper->mapToPhpParserNode($unionType, $typeKind);
523-
}
524-
525521
return null;
526522
}
527523
}

rules-tests/Php80/Rector/FunctionLike/UnionTypesRector/Fixture/narrow_bool_false2.php.inc renamed to rules-tests/Php80/Rector/FunctionLike/UnionTypesRector/Fixture/skip_narrow_bool_false_another_type.php.inc

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Rector\Tests\Php80\Rector\FunctionLike\UnionTypesRector\Fixture;
44

5-
class NarrowBoolFalse2
5+
class SkipNarrowBoolFalseAnotherType
66
{
77
/**
88
* @param bool|int|false $param
@@ -17,23 +17,3 @@ class NarrowBoolFalse2
1717
return 1;
1818
}
1919
}
20-
21-
?>
22-
-----
23-
<?php
24-
25-
namespace Rector\Tests\Php80\Rector\FunctionLike\UnionTypesRector\Fixture;
26-
27-
class NarrowBoolFalse2
28-
{
29-
public function go(bool|int $param): bool|int
30-
{
31-
if (rand(0, 1)) {
32-
return rand(0, 1) ? true : false;
33-
}
34-
35-
return 1;
36-
}
37-
}
38-
39-
?>

0 commit comments

Comments
 (0)