Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Narrow phpstan types in assertInstanceOf* AbstractTestCase methods #2879

Merged
merged 1 commit into from Nov 4, 2023

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Nov 4, 2023

before this PR, PHPStan did not narrow the type of the arg given to e.g. assertInstanceOfCarbon

example taken from ToArrayTest:

        \PHPStan\dumpType($date); // line 100
        $this->assertInstanceOfCarbon($date ?? null);
        \PHPStan\dumpType($date); // line 102

before this PR

------ ------------------------------------------ 
  Line   ToArrayTest.php                           
 ------ ------------------------------------------ 
  100    Dumped type: Carbon\CarbonInterface|null  
  102    Dumped type: Carbon\CarbonInterface|null  
 ------ ------------------------------------------ 

after this PR

------ ------------------------------------------ 
  Line   ToArrayTest.php                           
 ------ ------------------------------------------ 
  100    Dumped type: Carbon\CarbonInterface|null  
  102    Dumped type: Carbon\CarbonInterface
 ------ ------------------------------------------ 

PHPStan now can narrow the non-null part in line 102, which will help preventing false-positives on higher PHPStan levels

@kylekatarnls kylekatarnls merged commit 93f36e7 into briannesbitt:master Nov 4, 2023
56 checks passed
@staabm staabm deleted the phpstan branch November 4, 2023 16:58
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.

None yet

2 participants