0

Hey, I wanna check if there is some documentation about the code style for magento, specially regarding the best practices Indentation style for magento.

I will give 2 examples, and I wanna also know the opion of the community about it.

  1. Using PSR1/PS2 from phpstorm code style. (I believe it it's similar to the Magento 2)
$variable1 = "test";
$variableVariable2 = "test";
$variableVariable3 = "test";
$variableVariableVariable4 = "test";
  1. Some custom code style that I found. (I don't think it's common see it on Magento 2 projects)
$variable1                 = "test";
$variableVariable2         = "test";
$variableVariable3         = "test";
$variableVariableVariable4 = "test";

I looked the documentation and I didn't find anything related to it. But based on what I saw in the project, it was buit using the Option 1. I just wanna make sure that is the option 1 the correct one, or if there is some sense about it, some documentation or article, anything is welcome.

Thanks.

2 Answers 2

0

Configuring for Magento Coding Standard
Verify it is installed with vendor/bin/phpcs -i . You should see Magento2 in the output. Go to PHPStorm preferences > Editor > Inspections, and in the adjacent window go to PHP > Quality Tools > PHP_CodeSniffer validation. Under the Coding Standard dropdown, select Magento2
Refer to this link:- https://mirasvit.com/blog/guide-for-setting-up-phpstorm-for-magento-2-developments.html

1
  • Thank you. It was very usefull. Just a quick note. It was not showing Magento2 as option before. I had to go to "Preferences > PHP > Quality Tools > PHP_CodeSniffer > (Than I had to create clickin in the + icon a new interpreter and I chosen phpfpm from docker, there I inserted PHP_CodeSniffer path: /var/www/html/vendor/bin/phpcs, because I am using markshust/docker-magento).
    – Pedro Lima
    Commented Jan 24, 2023 at 22:09
0

There PHP code sniffer tool available which contain the sets of Magento rules. You can install it within Magento project: https://github.com/magento/magento-coding-standard.

All suggestions are fixable using the CLI command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.