Error Identifier: method.nameCase
Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.
Code example #
<?php declare(strict_types = 1);
class Foo
{
public function fooBar(): void
{
}
}
function (Foo $foo): void {
$foo->foobar(); // error: Call to method Foo::fooBar() with incorrect case: foobar
};
Why is it reported? #
While PHP method names are case-insensitive and foobar() will work at runtime, using a different case than the method declaration is inconsistent and makes code harder to read and maintain. This check helps enforce consistent casing across the codebase.
This error is reported only when the checkFunctionNameCase option is enabled.
How to fix it #
Use the exact same casing as in the method declaration.
function (Foo $foo): void {
- $foo->foobar();
+ $foo->fooBar();
};
How to ignore this error #
You can use the identifier method.nameCase to ignore this error using a comment:
// @phpstan-ignore method.nameCase
codeThatProducesTheError();
You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:
parameters:
ignoreErrors:
-
identifier: method.nameCase
Rules that report this error #
- PHPStan\Rules\Methods\CallMethodsRule [1]
- PHPStan\Rules\Methods\MethodCallableRule [1]
- PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule [1] phpstan/phpstan-strict-rules
- PHPStan\Rules\PHPUnit\DataProviderDataRule [1] phpstan/phpstan-phpunit
- PHPStan\Rules\PHPUnit\DataProviderDeclarationRule [1] phpstan/phpstan-phpunit