installation.rst 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. ============
  2. Installation
  3. ============
  4. When developing on multiple projects or with team of developers, it is highly recommended to install PHP CS Fixer as direct dependency per project and not globally on your machine.
  5. This will ensure each team member is using version of the tool expected by given project.
  6. PHP needs to be a minimum version of PHP 7.4.
  7. Composer
  8. --------
  9. Fresh installation
  10. ~~~~~~~~~~~~~~~~~~
  11. To install PHP CS Fixer, `install Composer <https://getcomposer.org/download/>`_ and issue the following command:
  12. .. code-block:: console
  13. composer require --dev friendsofphp/php-cs-fixer
  14. ## or when facing conflicts in dependencies:
  15. composer require --dev php-cs-fixer/shim
  16. Upgrade
  17. ~~~~~~~
  18. .. code-block:: console
  19. composer upgrade friendsofphp/php-cs-fixer
  20. ## or
  21. composer upgrade php-cs-fixer/shim
  22. Docker
  23. ------
  24. You can use pre-built Docker images to run ``php-cs-fixer``.
  25. .. code-block:: console
  26. docker run -it --rm -v $(pwd):/code ghcr.io/php-cs-fixer/php-cs-fixer:${FIXER_VERSION:-3-php8.3} fix src
  27. ``$FIXER_VERSION`` used in example above is an identifier of a release you want to use, which is based on Fixer and PHP versions combined. There are different tags for each Fixer's SemVer level and PHP version with syntax ``<php-cs-fixer-version>-php<php-version>``. For example:
  28. * ``3.66.1-php7.4``
  29. * ``3.66-php8.0``
  30. * ``3-php8.3``
  31. PHIVE
  32. -----
  33. Fresh installation
  34. ~~~~~~~~~~~~~~~~~~
  35. Install `PHIVE <https://phar.io>`_ and issue the following command:
  36. .. code-block:: console
  37. phive install php-cs-fixer
  38. Upgrade
  39. ~~~~~~~
  40. .. code-block:: console
  41. phive update php-cs-fixer
  42. GitHub Action (Docker)
  43. ----------------------
  44. To integrate PHP CS Fixer as check into a GitHub Action step, you can use a configuration like this:
  45. .. code-block:: yaml
  46. - name: PHP-CS-Fixer
  47. uses: docker://ghcr.io/php-cs-fixer/php-cs-fixer:3-php8.3
  48. with:
  49. args: check
  50. # use `check .` if your repository not having paths configured in .php-cs-fixer[.dist].php
  51. Gitlab-CI (Docker)
  52. ------------------
  53. To integrate PHP CS Fixer as check into Gitlab-CI, you can use a configuration like this:
  54. .. code-block:: yaml
  55. php-cs-fixer:
  56. image: ghcr.io/php-cs-fixer/php-cs-fixer:${FIXER_VERSION:-3-php8.3}
  57. script:
  58. php-cs-fixer check --format gitlab
  59. # use `check .` if your repository not having paths configured in .php-cs-fixer[.dist].php
  60. Homebrew (globally)
  61. -------------------
  62. While not recommended to install the tool globally, it is possible to use homebrew as well.
  63. Fresh installation
  64. ~~~~~~~~~~~~~~~~~~
  65. .. code-block:: console
  66. brew install php-cs-fixer
  67. Upgrade
  68. ~~~~~~~
  69. .. code-block:: console
  70. brew upgrade php-cs-fixer
  71. Manual binary download
  72. ----------------------
  73. It is also possible to download the `php-cs-fixer.phar`_ file and store it somewhere on your computer.
  74. Fresh installation
  75. ~~~~~~~~~~~~~~~~~~
  76. To do that, you can run these commands to easily access latest ``php-cs-fixer`` from anywhere on
  77. your system:
  78. .. code-block:: console
  79. wget https://cs.symfony.com/download/php-cs-fixer-v3.phar -O php-cs-fixer
  80. # or
  81. curl -L https://cs.symfony.com/download/php-cs-fixer-v3.phar -o php-cs-fixer
  82. or with specified version:
  83. .. code-block:: console
  84. wget https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases/download/v3.66.0/php-cs-fixer.phar -O php-cs-fixer
  85. # or
  86. curl -L https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases/download/v3.66.0/php-cs-fixer.phar -o php-cs-fixer
  87. then:
  88. .. code-block:: console
  89. sudo chmod a+x php-cs-fixer
  90. sudo mv php-cs-fixer /usr/local/bin/php-cs-fixer
  91. Then, just run ``php-cs-fixer``.
  92. Upgrade
  93. ~~~~~~~
  94. .. code-block:: console
  95. sudo php-cs-fixer self-update
  96. .. _php-cs-fixer.phar: https://cs.symfony.com/download/php-cs-fixer-v3.phar