2

I am already using phpcs/phpcbf for sniffing my code. Unfortunately, I cannot find a tool or a rule for PHPCS which can automatically organize my imports. I know something like this exists for IDE's like PhpStorm, but I want it to make use of it within our CI/CD, too.

I want to do the following:

namespace A;

new \My\Custom\Class(new \Exception);
new \My\Custom\AnotherClass();
$a = \strlen("Test");

↓ ↓ ↓ ↓

namespace A;

use My\Custom\{Class, AnotherClass};
use Exception;
use function strlen;

new Class(new Exception);
new AnotherClass();
$a = strlen("Test");

Does something like this exist?

Matthias Günter
  • 617
  • 8
  • 24
  • This is something that absolutely should be done in your IDE or text editor. Most of them will support organising imports. You don’t want to be doing it in your CI pipeline because then it’s going to be modifying checked-in code. – Martin Bean Dec 17 '21 at 11:23
  • 1
    I agree with Martin in this is not something you want to do automatically in a pipeline but I disagree with him that it has to be done in the IDE because command line tools exist for that, like [php-cs-fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer). – Daniel W. Dec 17 '21 at 11:57
  • The reason for not using this in the IDE is, that I am also using e.g. PHP-Scoper, which does, in fact, put FQN inline the PHP code while build process. – Matthias Günter Dec 17 '21 at 12:42

0 Answers0