-
Notifications
You must be signed in to change notification settings - Fork 574
Mark class_exists, interface_exists, trait_exists, and enum_exists as having no side effects in function metadata
#5607
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
Open
phpstan-bot
wants to merge
9
commits into
phpstan:2.1.x
Choose a base branch
from
phpstan-bot:create-pull-request/patch-625e02d
base: 2.1.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b4d52e3
Mark `class_exists`, `interface_exists`, `trait_exists`, and `enum_ex…
VincentLanglet 55155a6
Use AlwaysRememberedExpr to bypass impurity check for class_exists ty…
phpstan-bot 7913a40
Add test ensuring class_exists false result is not always remembered
phpstan-bot 643624b
Convert Bug8579Test to standard rule test and assertType test
phpstan-bot fca5425
Add assertType inside if branches for class_exists do-not-remember test
phpstan-bot cbbbf0b
Add interface_exists/trait_exists/enum_exists tests and fix nsrt asse…
phpstan-bot 6c0596a
Document AlwaysRememberedExpr with class-level PHPDoc
phpstan-bot 4f2b372
Add tests for interface_exists, trait_exists, and enum_exists with re…
phpstan-bot 5ca07a2
Shorten AlwaysRememberedExpr PHPDoc to be generic about its purpose
phpstan-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
tests/PHPStan/Rules/Classes/InstantiationDoNotRememberPossiblyImpureValuesRuleTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace PHPStan\Rules\Classes; | ||
|
|
||
| use PHPStan\Rules\Rule; | ||
| use PHPStan\Testing\RuleTestCase; | ||
| use function array_merge; | ||
|
|
||
| /** | ||
| * @extends RuleTestCase<InstantiationRule> | ||
| */ | ||
| class InstantiationDoNotRememberPossiblyImpureValuesRuleTest extends RuleTestCase | ||
| { | ||
|
|
||
| protected function getRule(): Rule | ||
| { | ||
| return self::getContainer()->getByType(InstantiationRule::class); | ||
| } | ||
|
|
||
| public function testBug8579(): void | ||
| { | ||
| $this->analyse([__DIR__ . '/data/bug-8579.php'], []); | ||
| } | ||
|
|
||
| public static function getAdditionalConfigFiles(): array | ||
| { | ||
| return array_merge( | ||
| parent::getAdditionalConfigFiles(), | ||
| [ | ||
| __DIR__ . '/doNotRememberPossiblyImpureValues.neon', | ||
| ], | ||
| ); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php | ||
|
|
||
| if (!class_exists('NonexistentClassBug8579')) throw new \Exception('nonexistentclass'); | ||
| $x = new \NonexistentClassBug8579(); | ||
|
|
||
| if (!interface_exists('NonexistentInterfaceBug8579')) throw new \Exception('nonexistentinterface'); | ||
| $x = new \NonexistentInterfaceBug8579(); | ||
|
|
||
| if (!trait_exists('NonexistentTraitBug8579')) throw new \Exception('nonexistenttrait'); | ||
| $x = new \NonexistentTraitBug8579(); | ||
|
|
||
| if (!enum_exists('NonexistentEnumBug8579')) throw new \Exception('nonexistentenum'); | ||
| $x = new \NonexistentEnumBug8579(); |
2 changes: 2 additions & 0 deletions
2
tests/PHPStan/Rules/Classes/doNotRememberPossiblyImpureValues.neon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| parameters: | ||
| rememberPossiblyImpureFunctionValues: false |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.