extdn / extdn-phpcs

PHP CodeSniffer rules
81 stars 10 forks source link

Rule: Check Module file structure #30

Open larsroettig opened 6 years ago

larsroettig commented 6 years ago

A typical file structure for a Magento 2 module shoul look like the following:

image

For this reason, we a should add a warning if in main an unexpected dir.

Expected dirs:

Dokumentation:

https://devdocs.magento.com/guides/v2.2/extension-dev-guide/build/module-file-structure.html

fooman commented 6 years ago

Thanks for bringing this up.

I generally agree that we should check for expected folder structure. I however would like to include a discussion (including with Magento) what this folder structure should be in the first place.

In particular should Magento go its own way (again) or should it follow where PHP as a whole seems to be heading. For example: On structuring PHP projects and php-pds

One issue which I think is currently insufficiently catered for is the question how are tests distributed in a standardised way. The current Test folder covers unit tests but there is no established way on how to for example distribute integration and functional tests (this will be important for the new MFTF tests as well).

schmengler commented 6 years ago

In particular should Magento go its own way (again) or should it follow where PHP as a whole seems to be heading. For example: On structuring PHP projects and php-pds

+1 for php-pds. We should not enforce the same standards for extensions as for core modules, those have different needs. Although in an ideal world, we'd have really modular core modules that could follow php-pds as well.

schmengler commented 6 years ago

@fooman the article also brings up a good point: "group by archetype" vs. "group by feature": Magento still follows the "group by archetype" pattern, just added more archetypes in Magento 2 (e.g. Api, Observer, Plugin). But other than in Magento 1, we are free to arrange our namespaces as we like, without constraints from the framework and I would not blindly follow the core here, which is not even consistent. I'd love to see our own reasonable guidelines for namespacing, though. This will need more discussion

schmengler commented 6 years ago

And one my favorite topics: framework independent domain code. I'd hate cramming this into Model, and it's not always reasonable to move it into its own repository. If you have a good argument against custom namespaces at the top module level for framework independent code, please let me know.

schmengler commented 6 years ago

https://devdocs.magento.com/guides/v2.2/extension-dev-guide/build/module-file-structure.html

Even this documentation is remarkably vague:

A typical file structure for a Magento 2 module can look like the following:

Following are some common module directories: