group_import.rst 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. =====================
  2. Rule ``group_import``
  3. =====================
  4. There MUST be group use for the same namespaces.
  5. Configuration
  6. -------------
  7. ``group_types``
  8. ~~~~~~~~~~~~~~~
  9. Defines the order of import types.
  10. Allowed types: ``list<string>``
  11. Default value: ``['classy', 'functions', 'constants']``
  12. Examples
  13. --------
  14. Example #1
  15. ~~~~~~~~~~
  16. *Default* configuration.
  17. .. code-block:: diff
  18. --- Original
  19. +++ New
  20. <?php
  21. -use Foo\Bar;
  22. -use Foo\Baz;
  23. +use Foo\{Bar, Baz};
  24. Example #2
  25. ~~~~~~~~~~
  26. With configuration: ``['group_types' => ['classy']]``.
  27. .. code-block:: diff
  28. --- Original
  29. +++ New
  30. <?php
  31. -use A\Foo;
  32. use function B\foo;
  33. -use A\Bar;
  34. +use A\{Bar, Foo};
  35. use function B\bar;
  36. References
  37. ----------
  38. - Fixer class: `PhpCsFixer\\Fixer\\Import\\GroupImportFixer <./../../../src/Fixer/Import/GroupImportFixer.php>`_
  39. - Test class: `PhpCsFixer\\Tests\\Fixer\\Import\\GroupImportFixerTest <./../../../tests/Fixer/Import/GroupImportFixerTest.php>`_
  40. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.