Skip to content

Commit 266535b

Browse files
committed
Allow single letters for parameter names
1 parent 925dc45 commit 266535b

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

src/Nexus/PHPStan/Rules/Functions/FunctionNamingRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function processNode(Node $node, Scope $scope): array
7272
continue; // @codeCoverageIgnore
7373
}
7474

75-
if (preg_match('/^[a-z][a-zA-Z0-9]+$/', $param->var->name) !== 1) {
75+
if (preg_match('/^[a-z][a-zA-Z0-9]*$/', $param->var->name) !== 1) {
7676
$errors[] = RuleErrorBuilder::message(\sprintf(
7777
'Parameter #%d $%s of function %s() should be in camelCase format.',
7878
$index + 1,

src/Nexus/PHPStan/Rules/Methods/MethodNamingRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function processNode(Node $node, Scope $scope): array
9494
continue; // @codeCoverageIgnore
9595
}
9696

97-
if (preg_match('/^[a-z][a-zA-Z0-9]+$/', $param->var->name) !== 1) {
97+
if (preg_match('/^[a-z][a-zA-Z0-9]*$/', $param->var->name) !== 1) {
9898
$errors[] = RuleErrorBuilder::message(\sprintf(
9999
'Parameter #%d $%s of %s::%s() should be in camelCase with no underscores.',
100100
$index + 1,

tests/PHPStan/Rules/Functions/FunctionNamingRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function testRule(): void
4545
],
4646
[
4747
'Function deride() should be namespaced using the "Nexus\\" namespace.',
48-
20,
48+
25,
4949
],
5050
]);
5151
}

tests/PHPStan/Rules/Functions/data/function-naming.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ function foo(
1414
): string {
1515
return $_bar;
1616
}
17+
18+
function baz(string $i): void
19+
{
20+
echo $i;
21+
}
1722
}
1823

1924
namespace {

tests/PHPStan/Rules/Methods/data/method-naming.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ public function _boo(): void {}
2020
public function base_band(): void {}
2121

2222
abstract public function readline(int $max_lifetime): void;
23+
24+
protected function baziter(int $i): int
25+
{
26+
return $i;
27+
}
2328
}

0 commit comments

Comments
 (0)