coding-standards
coding-standards copied to clipboard
PHP: PSR-1 asks for constants to be all upper case
Is there an existing issue for this?
- [X] I have searched the existing issues
Is your feature request related to a problem? Please describe
This should not be valid PHP code as the class constant Permissions is not upper case.
final class TablePermissionElement extends AbstractFormElement
{
private const Permissions = [];
}
Describe the solution you'd like
Maybe a PHP CS Fixer rule can be implemented to fix it to:
final class TablePermissionElement extends AbstractFormElement
{
private const PERMISSIONS = [];
}
E.g. symplify/phpstan-rules: Rules/UppercaseConstantRule
Describe alternatives you've considered
No response
Additional context
There are no hard rules but TYPO3 follows coding standards.
PSR-1: Basic Coding Standard
- Class constants MUST be declared in all upper case with underscore separators. https://www.php-fig.org/psr/psr-1/#1-overview
TYPO3 coding standards
https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/CodingGuidelines/CglPhp/GeneralRequirementsForPhpFiles.html#typo3-coding-standards
The package TYPO3 Coding Standards provides the most up-to-date recommendation for using and enforcing common coding guidelines, which are continuously improved. The package also offers toolchain configuration for automatically adjusting code to these standards. Specifically, a PHP CS Fixer configuration is provided, that is based on PER-CS1.0 (PSR-12) at the time of this writing, and transitioning towards PER-CS2.0.
PSR-12: Extended Coding Style & PER Coding Style 2.0
https://www.php-fig.org/psr/psr-12/#21-basic-coding-standard https://www.php-fig.org/per/coding-style/#2-general
2.1 Basic Coding Standard
Code MUST follow all rules outlined in PSR-1.
Hey @rr-it ,
IMHO this is a php-cs-fixer issue, as our ruleset requires PSR-1, this should be dealt with in PHP-CS-Fixer directly.
PHP CS Fixer will not implement this: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/6056#issuecomment-951743373
Naming classes as files following PSR1 is one of these good conventions. The scope of this project [PHP CS Fixer] is to change code into the style configured or make changes to optimize the code etc.
So the idea of having this standard enforced through warnings in your CI is great, however this [PHP CS Fixer] is just not the tool to do it with.
About custom PHPStan rules: are those part of the TYPO3 core or should they become part of this repository?
PHPStan (extensions) won't be part of this package for the time being, as this typo3/coding-standards is related to coding guidelines, not really static analysis of so many more aspects.