Skip to content
Advertisement

How do I prevent PHP CS Fixer from fixing specific function names?

When using PHP CS Fixer to resolve syntax errors on file save and using the Symfony rule set, any function names that are not camelCase will be corrected (as expected).

However when writing PHP Unit based tests, it’s often common practice to make the function names snake_case. This normally means that PHP CS Fixer will resolve the issue automatically, even when not required.

Is there a specific annotation that can be placed above a function to prevent this?

Advertisement

Answer

PHP CS Fixer does not have a rule to change all function names from snake_case to camelCase.

However, there is a rule php_unit_method_casing which enforces camel (or snake) case for PHPUnit test methods, and in Symfony rule set it’s used with default value, which is camel case.

This is what you want to change, by overriding the rule from Symfony rule set with non-default version:

[
    'php_unit_method_casing' => ['case' => 'snake_case'],
],
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement