diff --git a/src/Nexus/PHPStan/Rules/Functions/FunctionNamingRule.php b/src/Nexus/PHPStan/Rules/Functions/FunctionNamingRule.php index 69a7e25..9cf1f31 100644 --- a/src/Nexus/PHPStan/Rules/Functions/FunctionNamingRule.php +++ b/src/Nexus/PHPStan/Rules/Functions/FunctionNamingRule.php @@ -72,7 +72,7 @@ public function processNode(Node $node, Scope $scope): array continue; // @codeCoverageIgnore } - if (preg_match('/^[a-z][a-zA-Z0-9]+$/', $param->var->name) !== 1) { + if (preg_match('/^[a-z][a-zA-Z0-9]*$/', $param->var->name) !== 1) { $errors[] = RuleErrorBuilder::message(\sprintf( 'Parameter #%d $%s of function %s() should be in camelCase format.', $index + 1, diff --git a/src/Nexus/PHPStan/Rules/Methods/MethodNamingRule.php b/src/Nexus/PHPStan/Rules/Methods/MethodNamingRule.php index 4a66e8a..3bb8c94 100644 --- a/src/Nexus/PHPStan/Rules/Methods/MethodNamingRule.php +++ b/src/Nexus/PHPStan/Rules/Methods/MethodNamingRule.php @@ -94,7 +94,7 @@ public function processNode(Node $node, Scope $scope): array continue; // @codeCoverageIgnore } - if (preg_match('/^[a-z][a-zA-Z0-9]+$/', $param->var->name) !== 1) { + if (preg_match('/^[a-z][a-zA-Z0-9]*$/', $param->var->name) !== 1) { $errors[] = RuleErrorBuilder::message(\sprintf( 'Parameter #%d $%s of %s::%s() should be in camelCase with no underscores.', $index + 1, diff --git a/tests/PHPStan/Rules/Functions/FunctionNamingRuleTest.php b/tests/PHPStan/Rules/Functions/FunctionNamingRuleTest.php index de727b4..cc224aa 100644 --- a/tests/PHPStan/Rules/Functions/FunctionNamingRuleTest.php +++ b/tests/PHPStan/Rules/Functions/FunctionNamingRuleTest.php @@ -45,7 +45,7 @@ public function testRule(): void ], [ 'Function deride() should be namespaced using the "Nexus\\" namespace.', - 20, + 25, ], ]); } diff --git a/tests/PHPStan/Rules/Functions/data/function-naming.php b/tests/PHPStan/Rules/Functions/data/function-naming.php index f4d2500..92a82dc 100644 --- a/tests/PHPStan/Rules/Functions/data/function-naming.php +++ b/tests/PHPStan/Rules/Functions/data/function-naming.php @@ -14,6 +14,11 @@ function foo( ): string { return $_bar; } + + function baz(string $i): void + { + echo $i; + } } namespace { diff --git a/tests/PHPStan/Rules/Methods/data/method-naming.php b/tests/PHPStan/Rules/Methods/data/method-naming.php index d25ffe3..4d3e774 100644 --- a/tests/PHPStan/Rules/Methods/data/method-naming.php +++ b/tests/PHPStan/Rules/Methods/data/method-naming.php @@ -20,4 +20,9 @@ public function _boo(): void {} public function base_band(): void {} abstract public function readline(int $max_lifetime): void; + + protected function baziter(int $i): int + { + return $i; + } }