single_import_per_statement.rst 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ====================================
  2. Rule ``single_import_per_statement``
  3. ====================================
  4. There MUST be one use keyword per declaration.
  5. Configuration
  6. -------------
  7. ``group_to_single_imports``
  8. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  9. Whether to change group imports into single imports.
  10. Allowed types: ``bool``
  11. Default value: ``true``
  12. Examples
  13. --------
  14. Example #1
  15. ~~~~~~~~~~
  16. *Default* configuration.
  17. .. code-block:: diff
  18. --- Original
  19. +++ New
  20. <?php
  21. -use Foo, Sample, Sample\Sample as Sample2;
  22. +use Foo;
  23. +use Sample;
  24. +use Sample\Sample as Sample2;
  25. Example #2
  26. ~~~~~~~~~~
  27. With configuration: ``['group_to_single_imports' => true]``.
  28. .. code-block:: diff
  29. --- Original
  30. +++ New
  31. <?php
  32. -use Space\Models\ {
  33. - TestModelA,
  34. - TestModelB,
  35. - TestModel,
  36. -};
  37. +use Space\Models\TestModelA;
  38. +use Space\Models\TestModelB;
  39. +use Space\Models\TestModel;
  40. Rule sets
  41. ---------
  42. The rule is part of the following rule sets:
  43. - `@PER <./../../ruleSets/PER.rst>`_ with config:
  44. ``['group_to_single_imports' => false]``
  45. - `@PER-CS <./../../ruleSets/PER-CS.rst>`_ with config:
  46. ``['group_to_single_imports' => false]``
  47. - `@PER-CS1.0 <./../../ruleSets/PER-CS1.0.rst>`_ with config:
  48. ``['group_to_single_imports' => false]``
  49. - `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_ with config:
  50. ``['group_to_single_imports' => false]``
  51. - `@PSR2 <./../../ruleSets/PSR2.rst>`_
  52. - `@PSR12 <./../../ruleSets/PSR12.rst>`_ with config:
  53. ``['group_to_single_imports' => false]``
  54. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_
  55. - `@Symfony <./../../ruleSets/Symfony.rst>`_
  56. References
  57. ----------
  58. - Fixer class: `PhpCsFixer\\Fixer\\Import\\SingleImportPerStatementFixer <./../../../src/Fixer/Import/SingleImportPerStatementFixer.php>`_
  59. - Test class: `PhpCsFixer\\Tests\\Fixer\\Import\\SingleImportPerStatementFixerTest <./../../../tests/Fixer/Import/SingleImportPerStatementFixerTest.php>`_
  60. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.