Skip to content

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

License

Notifications You must be signed in to change notification settings

erkenes/php-cs-fixer-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

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/[email protected]

      # PHP 8.2
      -
        name: Run PHP-CS-Fixer
        uses: erkenes/[email protected]

      # PHP 8.1
      -
        name: Run PHP-CS-Fixer
        uses: erkenes/[email protected]

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" \
  .