Skip to content

Github Action to check your code with PHP_CodeSniffer that can check only PR changed files or even lines

License

Notifications You must be signed in to change notification settings

thenabeel/action-phpcs

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 to run PHP_CodeSniffer of files changed in current PR or even on changed lines

This action was forked from the tinovyatkin/action-php-codesniffer

This action runs PHP_CodeSniffer on files changed in a Pull Request, by default annotating only lines changed by the PR author. So, it's fast and great to work with legacy code:

annotations

Contrary to some existing solutions this actions works faster than Docker based actions (as it runs from Node.JS directly in the same VM) and runs only on changed files (good for big projects with some non-conform files as well as to gradually introduce code style).

Usage

Add a file like this to .github/workflows/phpcs.yml:

name: "CI"

on:
  pull_request:
    paths:
      - "**.php"
      - "phpcs.xml"
      - ".github/workflows/phpcs.yml"

jobs:
  phpcs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0 # important!

      # we may use whatever way to install phpcs, just specify the path on the next step
      # however, curl seems to be the fastest
      - name: Install PHP_CodeSniffer
        run: |
          curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
          php phpcs.phar --version

      - uses: thenabeel/action-phpcs@v8
        with:
          files: "**.php" # you may customize glob as needed
          phpcs_path: php phpcs.phar
          standard: phpcs.xml

You also will need either to pick a build code style standard or create phpcs.xml file (like this for example). You may find all available configuration options at action.yml in this repository.

About

Github Action to check your code with PHP_CodeSniffer that can check only PR changed files or even lines

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 88.8%
  • PHP 8.1%
  • JavaScript 3.1%