Skip to content

Conversation

@samsonasik
Copy link
Member

@samsonasik samsonasik commented Dec 9, 2022

Make NullableType correctly applied when possible.

On TypedPropertyFromAssignsRector use case, it correctly apply type use ?DateTime instead of DateTime|null when types keys are not sorted (ensure sort after check types only 2, and one of them is null).

@samsonasik samsonasik changed the title [PHPStanStaticTypeMapper] Handle Nullable Type on UnionType on UnionTypeMapper when possible on php >= 7.4 [PHPStanStaticTypeMapper] Handle Nullable Type on UnionType on UnionTypeMapper when possible on php >= 7.1 Dec 9, 2022
@samsonasik samsonasik changed the title [PHPStanStaticTypeMapper] Handle Nullable Type on UnionType on UnionTypeMapper when possible on php >= 7.1 [PHPStanStaticTypeMapper] Handle Nullable Type on UnionType on UnionTypeMapper when possible Dec 9, 2022
@samsonasik
Copy link
Member Author

samsonasik commented Dec 9, 2022

The test error on AddFalseDefaultToBoolPropertyRector is caused by overlapped merged PR:

There was 1 failure:

1) Rector\Tests\CodingStyle\Rector\Property\AddFalseDefaultToBoolPropertyRector\AddFalseDefaultToBoolPropertyRectorTest::test with data set #4 ('/Users/samsonasik/www/rector-...hp.inc')
Failed asserting that string matches format description.
--- Expected
+++ Actual
@@ @@
     /**
      * @var bool
      */
-    private $property;
+    private $property = false;
 
     public function __construct(bool $property)

which the property is in Trait_, which actually, the __construct() is overrideable from class that consume it, see https://3v4l.org/hsB8k1#v7.0.28

@samsonasik
Copy link
Member Author

I fixed the test for __construct in trait usage, as the __construct can be overridden by class that consume it, https://3v4l.org/MZFmT#v7.0.28

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba it is ready for review.

@TomasVotruba
Copy link
Member

Looks good, thank you 👍

@TomasVotruba TomasVotruba merged commit 863fee3 into main Dec 9, 2022
@TomasVotruba TomasVotruba deleted the resolve-nullable-type-on-union-type branch December 9, 2022 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants