문제

I recently started working extensively with Magento and Code sniffer, and I would like to know which standards I should follow.

I tried Zend coding standards, but I don't want to use the 80 line limit, and it's not used in the core either.

After that, I tried CS2 standards, but that doesn't work either because of the _ in various functions, and class names, which have an _ in them, and don't have namespaces.

So, is there another standard that the core code complies 100% with ? If not, shouldn't magento have its own coding standards? It has its own stackexchange site, some well defined coding standards would be welcome to be used by extension developers.

도움이 되었습니까?

해결책

다른 팁

Magento best practices are quite good described by Josh Pratt here. He suggests to adopt and follow the Zend Code Style Standards and I can only join him.

The maximal line length is not a strict requirement. However from readability point of view too long lines are not encouraged.

Here are latest Magento marketplace coding standard for Magento1 and Magento2

MEQP2 For Magento2

MEQP1 For Magento1

https://github.com/magento/marketplace-eqp

I'd like to submit that we should be using the Magento 2 code sniff as a standard for both Magento 1.X and 2.X: https://github.com/cobhimself/phpcs-magento-rules/blob/master/ruleset.xml

And here's essentially a mirror of that ruleset as a standalone repository: https://github.com/cobhimself/phpcs-magento-rules

This post is a bit old (2008) but I guess that it's still valid:

Is Magento following the ZF coding standards? Yes

With few exceptions, such as:

  • short open tags are allowed in templates.
  • concatenation dots are not enclosed in spaces.
  • indentation for for long lines hard wraps should be always one soft tab forward.

Edit As Tim worte in comment there are no short open tags in Magento core templatesa and it's best not to use them anyway as they are not recommanded (see here).

But my advice to you... Since you are writing your own module use your own coding style. From my experience you will make less mistakes when writing code in your own style, that you are familiar with, than if you follow Magento coding style one day and e.g. Wordpress coding style the next just because you are writing a module for a different website project.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top