-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
define: case_insensitive is ignored, case-insensitive constants are n…
…o longer supported
- Loading branch information
Showing
5 changed files
with
98 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Rules\Functions; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Expr\FuncCall; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Php\PhpVersion; | ||
use PHPStan\Rules\RuleErrorBuilder; | ||
|
||
/** | ||
* @implements \PHPStan\Rules\Rule<\PhpParser\Node\Expr\FuncCall> | ||
*/ | ||
class DefineParametersRule implements \PHPStan\Rules\Rule | ||
{ | ||
|
||
private PhpVersion $phpVersion; | ||
|
||
public function __construct(PhpVersion $phpVersion) | ||
{ | ||
$this->phpVersion = $phpVersion; | ||
} | ||
|
||
public function getNodeType(): string | ||
{ | ||
return FuncCall::class; | ||
} | ||
|
||
public function processNode(Node $node, Scope $scope): array | ||
{ | ||
if (!($node->name instanceof \PhpParser\Node\Name)) { | ||
return []; | ||
} | ||
if ($this->phpVersion->supportsCaseInsensitiveConstantNames()) { | ||
return []; | ||
} | ||
$name = strtolower((string) $node->name); | ||
if ($name !== 'define') { | ||
return []; | ||
} | ||
$args = $node->getArgs(); | ||
$argsCount = count($args); | ||
// Expects 2 or 3, 1 arg is caught by CallToFunctionParametersRule | ||
if ($argsCount < 3) { | ||
return []; | ||
} | ||
return [ | ||
RuleErrorBuilder::message( | ||
'Argument #3 ($case_insensitive) is ignored since declaration of case-insensitive constants is no longer supported.' | ||
)->line($node->getLine())->build(), | ||
]; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
tests/PHPStan/Rules/Functions/DefineParametersRuleTest.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,32 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Rules\Functions; | ||
|
||
use PHPStan\Php\PhpVersion; | ||
|
||
/** | ||
* @extends \PHPStan\Testing\RuleTestCase<DefineParametersRule> | ||
*/ | ||
class DefineParametersRuleTest extends \PHPStan\Testing\RuleTestCase | ||
{ | ||
|
||
protected function getRule(): \PHPStan\Rules\Rule | ||
{ | ||
return new DefineParametersRule(new PhpVersion(PHP_VERSION_ID)); | ||
} | ||
|
||
public function testFile(): void | ||
{ | ||
if (PHP_VERSION_ID < 80000) { | ||
$this->analyse([__DIR__ . '/data/call-to-define.php'], []); | ||
} else { | ||
$this->analyse([__DIR__ . '/data/call-to-define.php'], [ | ||
[ | ||
'Argument #3 ($case_insensitive) is ignored since declaration of case-insensitive constants is no longer supported.', | ||
3, | ||
], | ||
]); | ||
} | ||
} | ||
|
||
} |
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,6 @@ | ||
<?php | ||
|
||
define('CaSeInSeNsItIvE', 0, true); | ||
define('CaSeInSeNsItIvE_IsOK', 0); | ||
define('all_lowercase', 1); | ||
define('ALL_UPPERCASE', 1); |