-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not remember values of function with side effects
- Loading branch information
1 parent
edc8446
commit d4edc59
Showing
6 changed files
with
116 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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 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 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
72 changes: 72 additions & 0 deletions
72
tests/PHPStan/Analyser/data/do-not-remember-impure-functions.php
This file contains 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,72 @@ | ||
<?php | ||
|
||
namespace DoNotRememberImpureFunctions; | ||
|
||
use function PHPStan\Analyser\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
public function doFoo() | ||
{ | ||
function (): void { | ||
if (rand(0, 1)) { | ||
assertType('int', rand(0, 1)); | ||
} | ||
}; | ||
|
||
function (): void { | ||
if (rand(0, 1) === 0) { | ||
assertType('int', rand(0, 1)); | ||
} | ||
}; | ||
} | ||
|
||
public function doBar(): bool | ||
{ | ||
|
||
} | ||
|
||
/** @phpstan-pure */ | ||
public function doBaz(): bool | ||
{ | ||
|
||
} | ||
|
||
/** @phpstan-impure */ | ||
public function doLorem(): bool | ||
{ | ||
|
||
} | ||
|
||
public function doIpsum() | ||
{ | ||
if ($this->doBar() === true) { | ||
assertType('true', $this->doBar()); | ||
} | ||
|
||
if ($this->doBaz() === true) { | ||
assertType('true', $this->doBaz()); | ||
} | ||
|
||
if ($this->doLorem() === true) { | ||
assertType('bool', $this->doLorem()); | ||
} | ||
} | ||
|
||
public function doDolor() | ||
{ | ||
if ($this->doBar()) { | ||
assertType('true', $this->doBar()); | ||
} | ||
|
||
if ($this->doBaz()) { | ||
assertType('true', $this->doBaz()); | ||
} | ||
|
||
if ($this->doLorem()) { | ||
assertType('bool', $this->doLorem()); | ||
} | ||
} | ||
|
||
} |
This file contains 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 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