1

PhpStorm 2017.1, I want it to automatically group class imports - by Ctrl + Alt + L (or maybe there is some another option).

What I have:

use AppBundle\Entity\DailyTask;
use AppBundle\Entity\Event;
use AppBundle\Entity\Periodical;
use AppBundle\Entity\Ponder;
use AppBundle\Entity\Todo;
use AppBundle\Entity\Until;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

What I need to get as result:

use AppBundle\Entity\{DailyTask, Event, Periodical, Ponder, Todo, Until};
use Sensio\Bundle\FrameworkExtraBundle\Configuration\{Method, Route};

How to do this? As there more than year passed since PHP 7 introduced namespace grouping, I'm sure there must be such ability in the IDE.

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Audiophile
  • 970
  • 2
  • 8
  • 20
  • https://stackoverflow.com/questions/7121682/php-how-to-import-all-classes-from-another-namespace might answer your question. – Jhecht Jul 10 '17 at 17:08
  • 5
    https://blog.jetbrains.com/phpstorm/2016/04/group-use-statements-in-phpstorm-2016-1/ ... according to this it should work – ad_on_is Jul 10 '17 at 17:45
  • @ad_on_is , thanks, that's it! – Audiophile Jul 11 '17 at 07:53
  • I came here looking for how to disable grouping of imports :) The problem with grouping is you will have to deal with constant and painful to fix merge conflicts as your team grows. Single "use" statement per class is much less hassle because even if it does conflict you can just accept both sides and worst case you get an unused import – MeatPopsicle Nov 09 '22 at 15:42
  • can be this done as part of optimize imports or code analysis? – apedic Feb 20 '23 at 14:13

0 Answers0