EasyCodingStandard and PHPStan meet 3 Symfony E-Commerce Projects
Lines of code, Duplicated code, Cyclomatic complexity or Method length. These metrics are very rarely used in practise (even though there is a sniff for that).
I've updated the repository on Github with both tools, so you can verify all the results in this post locally.
(Tip: logos lead to projects' landing pages. Be sure to explore.)
When a project uses coding standards - moreover CI-checkers - it is very easy to contribute to it. I don't have to be afraid a PR gets rejected or at least postponed due to a wrong bracket position (yea, that happens).
|0 errors||9 723 errors||133 errors|
If you’re used to PSR2 style, you probably use PHPStorm to check it and contributing to Sylius would mean no extra work for you. Sylius' ruleset contains just handful of checkers though.
Spryker has own package just for coding-standard build on PHP_CodeSnifer, but they don't comply with some rules of PHP CS Fixer. This might be issue if you're in the Symfony world and you use that tool in your projects.
Shopsys has its own coding-standard package build on both tools - PHP CS Fixer and PHP_CodeSniffer - compatible with PSR-2. I'd say that's the best solution, because you have the least responsibility as a contributor. CI tools will handle the code style for you.
The full set looks like this:
# ecs.yml services: # use short array  PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer: syntax: short # drop dead code SlevomatCodingStandard\Sniffs\Classes\UnusedPrivateElementsSniff: ~ # drop dead use namespaces PhpCsFixer\Fixer\Import\NoUnusedImportsFixer: ~ # and sort them A→Z PhpCsFixer\Fixer\Import\OrderedImportsFixer: ~
And results for our 3 projects?
|39 errors||97 errors||7 errors|
There are 8 levels in PHPStan to this day - from 0 to 7. Level 0 being the starter and 7 the Mission Impossible for most projects.
If you never used this tools before, you probably don’t know how strict PHPStan is. Doctrine2 has now level 1 and successfully passes it, thanks to Majkl578. In order to get the idea of what had to be done, see the PR.
Do you want to add PHPStan to your project? Read this short intro.
To have an idea about real numbers, I picked results for lvl 0 and lvl 7:
|PHPStan levels \ Projects||Shopsys||Spryker||Sylius|
|0||1 406 errors||7 905 errors||1 404 errors|
|7||1 413 errors||12 977 errors||3 715 errors|
As you can see, both Shopsys and Sylius are doing great. Sylius is just falling bit behind in higher levels.
As we have seen in the previous article, not all the projects are of the same size. It might not be fair to Spryker to count only PHPStan violations as its codebase is considerably larger. If we count violations relative to the size of the project (measured in lines of code) the graph changes significantly:
Results for lvl 0 and lvl 7:
|Relative to LOC||Shopsys||Spryker||Sylius|
This point of view shows that, on the less strict levels of analysis, Sylius and Shopsys are ahead of Spryker in terms of PHPStan violations. During the second level of analysis this changes and number of problems found notably rises, only Shopsys stands out with less than a half of the issues of both other frameworks. This trend does not change even while moving to the higher levels of scrutiny from mr. PHPStan.
Shopsys has long way to passing level 7 with 0 errors, but it has still some time till the release to improve this.
❤️️ Do you like what I write about? Or do you hate it but enjoy discussion? 😠
You can support my writing by throwing a couple bucks at my Patreon