Skip to content
code

GitHub Action

CS-Fixer for PHP

php8.3-1.0.0 Latest version

CS-Fixer for PHP

code

CS-Fixer for PHP

Use PHP-CS-Fixer to fix your PHP code style

Installation

Copy and paste the following snippet into your .yml file.

              

- name: CS-Fixer for PHP

uses: erkenes/php-cs-fixer-action@php8.3-1.0.0

Learn more about this action in erkenes/php-cs-fixer-action

Choose a version

GitHub Action for PHP-CS-Fixer

With this action you can run PHP-CS-Fixer in your GitHub Actions workflow.

NOTE: If you didn't create a .php-cs-fixer.dist.php file, do that first before adding this workflow. An example of this file created by the creators of PHP-CS-Fixer can be found here.

Usage

Define your GitHub workflow.

# .github/workflows/php-cs-fixer.yml

name: PHP-CS-Fixer

on:
  pull_request:
    types: [review_requested, ready_for_review]

jobs:
  php-cs-fixer:
    name: PHP-CS-Fixer
    runs-on: ubuntu-latest
    steps:
      -
        uses: actions/checkout@v4

      -
        name: Run PHP-CS-Fixer
        uses: erkenes/php-cs-fixer-action@main

Use a specific version of PHP

You can specify the PHP version to use by adding it as a prefix to the action version.

# .github/workflows/php-cs-fixer.yml

name: PHP-CS-Fixer

on:
  pull_request:
    types: [review_requested, ready_for_review]

jobs:
  php-cs-fixer:
    name: PHP-CS-Fixer
    runs-on: ubuntu-latest
    steps:
      -
        uses: actions/checkout@v4

      # PHP 8.3 (equal to main)
      -
        name: Run PHP-CS-Fixer
        uses: erkenes/php-cs-fixer-action@php8.3-1.0.0

      # PHP 8.2
      -
        name: Run PHP-CS-Fixer
        uses: erkenes/php-cs-fixer-action@php8.2-1.0.0

      # PHP 8.1
      -
        name: Run PHP-CS-Fixer
        uses: erkenes/php-cs-fixer-action@php8.1-1.0.0

Use auto-commit

To commit the changes automatically to the branch of the pull request, you can use the following configuration:

# .github/workflows/php-cs-fixer.yml

jobs:
  php-cs-fixer:
    name: PHP-CS-Fixer
    runs-on: ubuntu-latest
    steps:
      -
        uses: actions/checkout@v4

      -
        name: Run PHP-CS-Fixer
        uses: erkenes/php-cs-fixer-action@main

      -
        uses: stefanzweifel/git-auto-commit-action@8621497c8c39c72f3e2a999a26b4ca1b5058a842
        with:
          commit_message: 'fix: Apply php-cs-fixer changes'

Local build for testing

docker build \
  --build-arg "PHP_VERSION=8.3" \
  --build-arg "PHP_CS_FIXER_VERSION=3.54.0" \
  --tag "erkenes/php-cs-fixer-action:local" \
  .