Code Monkey home page Code Monkey logo

pre-commit-php's Introduction

Hootsuite - PHP Pre-commit Hooks

Pre-commit scripts appropiate for any PHP project. These hooks are made as custom plugins under the pre-commit git hook framework.

Setup

Just add to your .pre-commit-config.yaml file with the following

- repo: [email protected]:hootsuite/pre-commit-php.git
  sha: 1.1.0
  hooks:
  - id: php-lint
  - id: php-unit
  - id: php-cs
    files: \.(php)$
    args: [--standard=PSR1 -p]
  - id: php-cbf
    files: \.(php)$
    args: [--standard=PSR1 -p]

Supported Hooks

php-lint

<<<<<<< HEAD
- repo: [email protected]:hootsuite/pre-commit-php.git
  sha: 1.1.0
  hooks:
  - id: php-lint

A bash script that runs php -l against stage files that are php. Assumes php is a global executable command. Will exit when it hits the first syntax error.

php-lint-all

- repo: [email protected]:hootsuite/pre-commit-php.git
  sha: 1.1.0
  hooks:
  - id: php-lint-all

A systems hook that just runs php -l against stage files that have the .php extension. Add the args: [-s first] in your .pre-commit-config.yaml to enable it to exit on the first error found.

php-unit

- repo: [email protected]:hootsuite/pre-commit-php.git
  sha: 1.1.0
  hooks:
  - id: php-unit

A bash script that will run the appropriate phpunit executable. It will assume

  • Find the executable to run at either vendor/bin/phpunit, phpunit or php phpunit.phar (in that exact order).
  • There is already a phpunit.xml in the root of the repo

Note in its current state, it will run the whole PHPUnit test as along as .php file was committed.

php-cs

- repo: [email protected]:hootsuite/pre-commit-php.git
  sha: 1.1.0
  hooks:
  - id: php-cs
    files: \.(php)$
    args: [--standard=PSR1 -p]

Similar pattern as the php-unit hook. A bash script that will run the appropriate PHP Code Sniffer executable.

It will assume that there is a valid PHP Code Sniffer executable at these locations, vendor/bin/phpcs, phpcs or php phpcs.phar (in that exact order).

The args property in your hook declaration can be used for pass any valid PHP Code Sniffer arguments. In the example above, it will run PHP Code Sniffer against only the staged php files with the PSR-1 and progress enabled.

If you have multiple standards or a comma in your args property, escape the comma character like so

php-cbf

- repo: [email protected]:hootsuite/pre-commit-php.git
  sha: 1.1.0
  hooks:
  - id: php-cs
    files: \.(php)$
    args: [--standard=PSR1 -p]

Similar pattern as the php-cs hook. A bash script that will run the appropriate PHP Code Sniffer executable and will try to fix errors if it can using phpcbf.

It will assume that there is a valid PHP Code Beautifier and Fixer executable at these locations, vendor/bin/phpcbf, phpcbf or php phpcbf.phar (in that exact order).

The args property in your hook declaration can be used for pass any valid PHP Code Sniffer arguments. In the example above, it will run PHP Code Sniffer against only the staged php files with the PSR-1 and progress enabled.

If you have multiple standards or a comma in your args property, escape the comma character like so

- repo: [email protected]:hootsuite/pre-commit-php.git
  sha: 1.1.0
  hooks:
  - id: php-cs
    files: \.(php)$
    args: ["--standard=PSR1/,path/to/ruleset.xml", "-p"]

To install PHP Codesniffer (phpcs & phpcbf), follow the recommended steps here.

php-cs-fixer

- repo: [email protected]:hootsuite/pre-commit-php.git
  sha: 1.1.0
  hooks:
  - id: php-cs-fixer
    files: \.(php)$
    args: [--level=PSR2]

Similar pattern as the php-cs hook. A bash script that will run the appropriate PHP Coding Standards Fixer executable and to fix errors according to the configuration. It accepts all of the args from the php-cs-fixer command, in particular the --level, --config, and --config-file options.

The tool will fail a build when it has made changes to the staged files. This allows a developer to do a git diff and examine the changes that it has made. Remember that you may omit this if needed with a SKIP=php-cs-fixer git commit.

pre-commit-php's People

Contributors

shihoonhootsuite avatar jaychakra avatar ixisandyr avatar craig-davis avatar warren5236 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.