-
Notifications
You must be signed in to change notification settings - Fork 574
Declare Memcached methods as impure #5536
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
Changes from all commits
673b3c7
315cbb8
96be53f
2edcb5e
199c942
347eca4
45f069f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @phpstan-all-methods-impure | ||
| */ | ||
| class Memcached {} | ||
|
|
||
| /** | ||
| * @phpstan-all-methods-impure | ||
| */ | ||
| class Memcache {} | ||
|
|
||
| /** | ||
| * @phpstan-all-methods-impure | ||
| */ | ||
| class MemcachePool {} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace PHPStan\Rules\Comparison; | ||
|
|
||
| use PHPStan\Analyser\RicherScopeGetTypeHelper; | ||
| use PHPStan\Rules\Rule; | ||
| use PHPStan\Testing\RuleTestCase; | ||
| use function array_merge; | ||
|
|
||
| /** | ||
| * @extends RuleTestCase<StrictComparisonOfDifferentTypesRule> | ||
| */ | ||
| class Bug14534Test extends RuleTestCase | ||
| { | ||
|
|
||
| protected function getRule(): Rule | ||
| { | ||
| return new StrictComparisonOfDifferentTypesRule( | ||
| self::getContainer()->getByType(RicherScopeGetTypeHelper::class), | ||
| new PossiblyImpureTipHelper(true), | ||
| true, | ||
| true, | ||
| true, | ||
| ); | ||
| } | ||
|
|
||
| public function testRule(): void | ||
| { | ||
| $this->analyse([__DIR__ . '/data/bug-14534.php'], []); | ||
| } | ||
|
|
||
| public static function getAdditionalConfigFiles(): array | ||
| { | ||
| return array_merge( | ||
| parent::getAdditionalConfigFiles(), | ||
| [__DIR__ . '/bug-14534.neon'], | ||
| ); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| parameters: | ||
| stubFiles: | ||
| - data/bug-14534.stub |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace Bug13444; | ||
|
|
||
| function sayStoreCas(string $key): void | ||
| { | ||
| $memcached = new \Memcached(); | ||
|
|
||
| do { | ||
| $extendedReturn = $memcached->get($key, null, \Memcached::GET_EXTENDED); | ||
|
|
||
| if ($memcached->getResultCode() !== \Memcached::RES_SUCCESS) { | ||
| return; | ||
| } | ||
|
|
||
| if (!is_array($extendedReturn) || !isset($extendedReturn['value']) || !isset($extendedReturn['cas'])) { | ||
| return; | ||
| } | ||
|
|
||
| $data = $extendedReturn['value']; | ||
| $cas = $extendedReturn['cas']; | ||
| \assert(is_float($cas)); | ||
|
|
||
| // Do some work on the data.. | ||
| $memcached->cas($cas, $key, $data); | ||
|
|
||
| } while ($memcached->getResultCode() !== \Memcached::RES_SUCCESS); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <?php | ||
|
|
||
| namespace Bug14534; | ||
|
|
||
| function test(\SplFileObject $spl): bool | ||
|
staabm marked this conversation as resolved.
|
||
| { | ||
| if ($spl->key() === 1) { | ||
| return $spl->key() === 1; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| function test2(\SplTempFileObject $spl): bool | ||
| { | ||
| if ($spl->key() === 1) { | ||
| return $spl->key() === 1; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @phpstan-all-methods-impure | ||
| */ | ||
| class SplFileObject {} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should/can
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a test file, it's just to prove that
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand yet, why we will not ship other that that this LGTM
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't know SplFileObject was impure, I never use this class. Feel free to refactor SplFileObject to use There is maybe more class which can be refactored the same way |
||
Uh oh!
There was an error while loading. Please reload this page.