get_class_to_class_keyword.rst 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. ===================================
  2. Rule ``get_class_to_class_keyword``
  3. ===================================
  4. Replace ``get_class`` calls on object variables with class keyword syntax.
  5. Warning
  6. -------
  7. Using this rule is risky
  8. ~~~~~~~~~~~~~~~~~~~~~~~~
  9. Risky if the ``get_class`` function is overridden.
  10. Examples
  11. --------
  12. Example #1
  13. ~~~~~~~~~~
  14. .. code-block:: diff
  15. --- Original
  16. +++ New
  17. <?php
  18. -get_class($a);
  19. +$a::class;
  20. Example #2
  21. ~~~~~~~~~~
  22. .. code-block:: diff
  23. --- Original
  24. +++ New
  25. <?php
  26. $date = new \DateTimeImmutable();
  27. -$class = get_class($date);
  28. +$class = $date::class;
  29. Rule sets
  30. ---------
  31. The rule is part of the following rule sets:
  32. - `@PHP80Migration:risky <./../../ruleSets/PHP80MigrationRisky.rst>`_
  33. - `@PHP82Migration:risky <./../../ruleSets/PHP82MigrationRisky.rst>`_
  34. - `@Symfony:risky <./../../ruleSets/SymfonyRisky.rst>`_
  35. References
  36. ----------
  37. - Fixer class: `PhpCsFixer\\Fixer\\LanguageConstruct\\GetClassToClassKeywordFixer <./../../../src/Fixer/LanguageConstruct/GetClassToClassKeywordFixer.php>`_
  38. - Test class: `PhpCsFixer\\Tests\\Fixer\\LanguageConstruct\\GetClassToClassKeywordFixerTest <./../../../tests/Fixer/LanguageConstruct/GetClassToClassKeywordFixerTest.php>`_
  39. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.