I'm working on a code quality automation with phpmd
, phpcs
and phpcpd
tools. The code sniffer has been set to --standard=PSR12
.
I was unable to find any details or recommendations in terms of the way how namespace imports and aliases should be defined:
- grouping with curly brackets or defining each one in a separate way (which at the moment is my biased suggestion)
- A-Z sorting
Eg:
use Foo\Bar\{ Lorem, Ipsum, Dolor };
vs:
use Foo\Bar\Dolor;
use Foo\Bar\Ipsum;
use Foo\Bar\Lorem;
If there's no standard recommendation I'm going to establish internal rule within my team, but if there is any, I'm happy to obey it.
There is a couple of rules regarding the namespaces, but none who explicitly calls for the order. However, this is stated regarding the depth when declaring them:
For a general rule, if it's not explicitly stated, then there is no standard. Either works.
You can read more about the existing rules here:
https://www.php-fig.org/psr/psr-12/