diff --git a/phpstan.neon b/phpstan.neon index 22d909f..5bab190 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -41,3 +41,13 @@ parameters: paths: - tests/PHPStan/ + # TODO remove when minimum PHPStan is bumped to ^2 + # PropertyProperty is the primary class in php-parser v4 (PHPStan 1.x) - no warning + # PropertyProperty is an alias to PropertyItem in php-parser v5 (PHPStan 2.x) - triggers these warnings + - message: '#Class PhpParser\\Node\\Stmt\\PropertyProperty not found\. It has been renamed to PhpParser\\Node\\PropertyItem#' + paths: + - src/PHPStan/Rules/PropertyNameIdToIDRule.php + - message: '#Fetching class constant class of deprecated class PhpParser\\Node\\Stmt\\PropertyProperty#' + paths: + - src/PHPStan/Rules/PropertyNameIdToIDRule.php + diff --git a/rules.neon b/rules.neon index 1d2d61b..f354ac3 100644 --- a/rules.neon +++ b/rules.neon @@ -2,6 +2,7 @@ rules: # TODO gradually enable those rules #- MLL\Utils\PHPStan\Rules\ThrowableClassNameRule #- MLL\Utils\PHPStan\Rules\VariableNameIdToIDRule +#- MLL\Utils\PHPStan\Rules\PropertyNameIdToIDRule #- MLL\Utils\PHPStan\Rules\MissingClosureParameterTypehintRule parameters: # https://github.com/spaze/phpstan-disallowed-calls/blob/main/docs/custom-rules.md diff --git a/src/PHPStan/Rules/PropertyNameIdToIDRule.php b/src/PHPStan/Rules/PropertyNameIdToIDRule.php new file mode 100644 index 0000000..865833c --- /dev/null +++ b/src/PHPStan/Rules/PropertyNameIdToIDRule.php @@ -0,0 +1,31 @@ +name->name; + } +} diff --git a/tests/PHPStan/CapitalizationOfIDRuleIntegrationTest.php b/tests/PHPStan/CapitalizationOfIDRuleIntegrationTest.php index 9061203..7393f98 100644 --- a/tests/PHPStan/CapitalizationOfIDRuleIntegrationTest.php +++ b/tests/PHPStan/CapitalizationOfIDRuleIntegrationTest.php @@ -19,13 +19,16 @@ public static function dataIntegrationTests(): iterable 'Name of Stmt_Class "LabIdProcessor" should use "ID" instead of "Id", rename it to "LabIDProcessor".', ], 7 => [ + 'Name of Stmt_PropertyProperty "$patientId" should use "ID" instead of "Id", rename it to "$patientID".', + ], + 9 => [ 'Name of Stmt_ClassMethod "getLabId" should use "ID" instead of "Id", rename it to "getLabID".', ], - 12 => [ + 14 => [ 'Name of Stmt_ClassMethod "processLabId" should use "ID" instead of "Id", rename it to "processLabID".', 'Name of Param "$labId" should use "ID" instead of "Id", rename it to "$labID".', ], - 14 => [ + 16 => [ 'Name of Expr_Variable "$sampleId" should use "ID" instead of "Id", rename it to "$sampleID".', 'Name of Expr_Variable "$labId" should use "ID" instead of "Id", rename it to "$labID".', ], diff --git a/tests/PHPStan/data/correct-capitalization.php b/tests/PHPStan/data/correct-capitalization.php index cc289f1..1a855e8 100644 --- a/tests/PHPStan/data/correct-capitalization.php +++ b/tests/PHPStan/data/correct-capitalization.php @@ -4,9 +4,11 @@ class CorrectCapitalization { + private int $patientID = 1; + public function getLabID(): int { - return 1; + return $this->patientID; } public function processLabID(int $labID): void diff --git a/tests/PHPStan/data/wrong-capitalization.php b/tests/PHPStan/data/wrong-capitalization.php index d0f511e..281202f 100644 --- a/tests/PHPStan/data/wrong-capitalization.php +++ b/tests/PHPStan/data/wrong-capitalization.php @@ -4,9 +4,11 @@ class LabIdProcessor { + private int $patientId = 1; + public function getLabId(): int { - return 1; + return $this->patientId; } public function processLabId(int $labId): void diff --git a/tests/PHPStan/phpstan-test.neon b/tests/PHPStan/phpstan-test.neon index 6f11355..b2b832b 100644 --- a/tests/PHPStan/phpstan-test.neon +++ b/tests/PHPStan/phpstan-test.neon @@ -6,3 +6,4 @@ rules: - MLL\Utils\PHPStan\Rules\ParameterNameIdToIDRule - MLL\Utils\PHPStan\Rules\MethodNameIdToIDRule - MLL\Utils\PHPStan\Rules\ClassNameIdToIDRule + - MLL\Utils\PHPStan\Rules\PropertyNameIdToIDRule