Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve conditional type resolving performance
- Loading branch information
Showing
5 changed files
with
118 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Rules; | ||
|
||
use PhpParser\Node; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Testing\RuleTestCase; | ||
|
||
/** | ||
* @extends RuleTestCase<Rule> | ||
*/ | ||
class SlowdownRuleTest extends RuleTestCase | ||
{ | ||
|
||
/** | ||
* @return Rule<Node> | ||
*/ | ||
protected function getRule(): Rule | ||
{ | ||
return new class implements Rule { | ||
|
||
public function getNodeType(): string | ||
{ | ||
return Node::class; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function processNode(Node $node, Scope $scope): array | ||
{ | ||
return []; | ||
} | ||
|
||
}; | ||
} | ||
|
||
public function testRule(): void | ||
{ | ||
$this->analyse([__DIR__ . '/data/1.9.x-slowdown.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
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,15 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Bug5803; | ||
|
||
function () { | ||
if (!($_GET['foo'])) { // if 'foo' is falsy, SET $var | ||
$var = "set"; | ||
} | ||
|
||
if ($_GET['foo']) { | ||
|
||
} else { | ||
echo $var; | ||
} | ||
}; |
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,39 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Foo; | ||
|
||
use function trim; | ||
|
||
class Foo | ||
{ | ||
|
||
public const FIELD_TITLE = 'title'; | ||
public const FIELD_SOURCE = 'source'; | ||
public const FIELD_BODY = 'body'; | ||
public const EMPTY_NOTE_BODY = '-'; | ||
|
||
public const FIELD_NOTES = 'notes'; | ||
public const SUBFIELD_NOTE = 'note'; | ||
|
||
/** | ||
* @param array<mixed> $data | ||
* @return array<mixed> | ||
*/ | ||
private function someMethod(array $data): array | ||
{ | ||
foreach ($data[self::FIELD_NOTES][self::SUBFIELD_NOTE] ?? [] as $index => $noteData) { | ||
$noteTitle = $noteData[self::FIELD_TITLE] ?? null; | ||
$noteSource = $noteData[self::FIELD_SOURCE] ?? null; | ||
$noteBody = $noteData[self::FIELD_BODY] ?? null; | ||
|
||
if ($noteBody === null || trim($noteBody) === '') { | ||
$data[self::FIELD_NOTES] = self::EMPTY_NOTE_BODY; | ||
} | ||
} | ||
|
||
if (isset($data[self::FIELD_NOTES][self::SUBFIELD_NOTE])) {} | ||
|
||
return $data; | ||
} | ||
|
||
} |