short_scalar_cast.rst 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ==========================
  2. Rule ``short_scalar_cast``
  3. ==========================
  4. Cast ``(boolean)`` and ``(integer)`` should be written as ``(bool)`` and
  5. ``(int)``, ``(double)`` and ``(real)`` as ``(float)``, ``(binary)`` as
  6. ``(string)``.
  7. Examples
  8. --------
  9. Example #1
  10. ~~~~~~~~~~
  11. .. code-block:: diff
  12. --- Original
  13. +++ New
  14. <?php
  15. -$a = (boolean) $b;
  16. -$a = (integer) $b;
  17. -$a = (double) $b;
  18. +$a = (bool) $b;
  19. +$a = (int) $b;
  20. +$a = (float) $b;
  21. -$a = (binary) $b;
  22. +$a = (string) $b;
  23. Rule sets
  24. ---------
  25. The rule is part of the following rule sets:
  26. - `@PER <./../../ruleSets/PER.rst>`_
  27. - `@PER-CS <./../../ruleSets/PER-CS.rst>`_
  28. - `@PER-CS1.0 <./../../ruleSets/PER-CS1.0.rst>`_
  29. - `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_
  30. - `@PHP74Migration <./../../ruleSets/PHP74Migration.rst>`_
  31. - `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_
  32. - `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_
  33. - `@PHP82Migration <./../../ruleSets/PHP82Migration.rst>`_
  34. - `@PHP83Migration <./../../ruleSets/PHP83Migration.rst>`_
  35. - `@PHP84Migration <./../../ruleSets/PHP84Migration.rst>`_
  36. - `@PSR12 <./../../ruleSets/PSR12.rst>`_
  37. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_
  38. - `@Symfony <./../../ruleSets/Symfony.rst>`_
  39. References
  40. ----------
  41. - Fixer class: `PhpCsFixer\\Fixer\\CastNotation\\ShortScalarCastFixer <./../../../src/Fixer/CastNotation/ShortScalarCastFixer.php>`_
  42. - Test class: `PhpCsFixer\\Tests\\Fixer\\CastNotation\\ShortScalarCastFixerTest <./../../../tests/Fixer/CastNotation/ShortScalarCastFixerTest.php>`_
  43. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.