Skip to content

Commit

Permalink
Allow single letters for parameter names
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Jan 6, 2025
1 parent 925dc45 commit 266535b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Nexus/PHPStan/Rules/Functions/FunctionNamingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Nexus/PHPStan/Rules/Methods/MethodNamingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Rules/Functions/FunctionNamingRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testRule(): void
],
[
'Function deride() should be namespaced using the "Nexus\\" namespace.',
20,
25,
],
]);
}
Expand Down
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/Functions/data/function-naming.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ function foo(
): string {
return $_bar;
}

function baz(string $i): void
{
echo $i;
}
}

namespace {
Expand Down
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/Methods/data/method-naming.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 266535b

Please sign in to comment.