psr_autoloading.rst 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ========================
  2. Rule ``psr_autoloading``
  3. ========================
  4. Classes must be in a path that matches their namespace, be at least one
  5. namespace deep and the class name should match the file name.
  6. Warning
  7. -------
  8. Using this rule is risky
  9. ~~~~~~~~~~~~~~~~~~~~~~~~
  10. This fixer may change your class name, which will break the code that depends on
  11. the old name.
  12. Configuration
  13. -------------
  14. ``dir``
  15. ~~~~~~~
  16. If provided, the directory where the project code is placed.
  17. Allowed types: ``null`` and ``string``
  18. Default value: ``null``
  19. Examples
  20. --------
  21. Example #1
  22. ~~~~~~~~~~
  23. *Default* configuration.
  24. .. code-block:: diff
  25. --- Original
  26. +++ New
  27. <?php
  28. namespace PhpCsFixer\FIXER\Basic;
  29. -class InvalidName {}
  30. +class PsrAutoloadingFixer {}
  31. Example #2
  32. ~~~~~~~~~~
  33. With configuration: ``['dir' => './src']``.
  34. .. code-block:: diff
  35. --- Original
  36. +++ New
  37. <?php
  38. -namespace PhpCsFixer\FIXER\Basic;
  39. -class InvalidName {}
  40. +namespace PhpCsFixer\Fixer\Basic;
  41. +class PsrAutoloadingFixer {}
  42. Rule sets
  43. ---------
  44. The rule is part of the following rule sets:
  45. - `@PhpCsFixer:risky <./../../ruleSets/PhpCsFixerRisky.rst>`_
  46. - `@Symfony:risky <./../../ruleSets/SymfonyRisky.rst>`_
  47. References
  48. ----------
  49. - Fixer class: `PhpCsFixer\\Fixer\\Basic\\PsrAutoloadingFixer <./../../../src/Fixer/Basic/PsrAutoloadingFixer.php>`_
  50. - Test class: `PhpCsFixer\\Tests\\Fixer\\Basic\\PsrAutoloadingFixerTest <./../../../tests/Fixer/Basic/PsrAutoloadingFixerTest.php>`_
  51. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.