Skip to content

Commit

Permalink
[Downgrade PHP 7.4] Add false to downgraded typed property (#1596)
Browse files Browse the repository at this point in the history
Co-authored-by: Ondrej Mirtes <[email protected]>
Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
3 people authored Dec 30, 2021
1 parent 8648410 commit 18fbe1d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/NodeTypeResolver/PHPStan/Type/TypeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public function createMixedPassedOrUnionTypeAndKeepConstant(array $types): Type
/**
* @param Type[] $types
*/
public function createMixedPassedOrUnionType(array $types): Type
public function createMixedPassedOrUnionType(array $types, bool $keepConstantTypes = false): Type
{
$types = $this->unwrapUnionedTypes($types);
$types = $this->uniquateTypes($types);
$types = $this->uniquateTypes($types, $keepConstantTypes);

return $this->createUnionOrSingleType($types);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public function mapToPHPStan(Node $node): Type
$types[] = $this->phpParserNodeMapper->mapToPHPStanType($unionedType);
}

return $this->typeFactory->createMixedPassedOrUnionType($types);
return $this->typeFactory->createMixedPassedOrUnionType($types, true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Rector\Tests\DowngradePhp74\Rector\Property\DowngradeTypedPropertyRector\Fixture;

class Foo
{

private Foo|Bar|false $prop;

}
?>
-----
<?php

namespace Rector\Tests\DowngradePhp74\Rector\Property\DowngradeTypedPropertyRector\Fixture;

class Foo
{

/**
* @var \Rector\Tests\DowngradePhp74\Rector\Property\DowngradeTypedPropertyRector\Fixture\Bar|\Rector\Tests\DowngradePhp74\Rector\Property\DowngradeTypedPropertyRector\Fixture\Foo|false
*/
private $prop;

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

namespace Rector\Tests\DowngradePhp80\Rector\Property\DowngradeUnionTypeTypedPropertyRector\Fixture;

class Foo
{

private Foo|Bar|false $prop;

}
?>
-----
<?php

namespace Rector\Tests\DowngradePhp80\Rector\Property\DowngradeUnionTypeTypedPropertyRector\Fixture;

class Foo
{

/**
* @var \Rector\Tests\DowngradePhp80\Rector\Property\DowngradeUnionTypeTypedPropertyRector\Fixture\Bar|\Rector\Tests\DowngradePhp80\Rector\Property\DowngradeUnionTypeTypedPropertyRector\Fixture\Foo|false
*/
private $prop;

}
?>
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ class DoNotCrashOnNumericStringNoReturnDeclaration
}
}

?>
?>

0 comments on commit 18fbe1d

Please sign in to comment.