Skip to content

allysonsilva/php-pre-commit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

GIT pre-commit script appropriate for any PHP project. A pre-commit script that validates syntax errors in PHP. It also validates PHP files against PSR2 coding styles.

About

This is a pre commit script that checks added, copied, modified or renamed files for syntax errors and PSR2 coding standards.

Installation

  1. git clone this repository.
  2. Copy the pre-commit file to your project's Git hooks folder. Make sure that the pre-commit file is executable.
# Put the pre-commit file in the .git/hooks/ folder in your git repository.
curl -O https://raw.githubusercontent.com/AllysonSilva/php-pre-commit/master/pre-commit

# create new hooks folder
mkdir .git/hooks

# move pre-commit to new hooks folder
mv pre-commit .git/hooks/pre-commit

# don't forget to make the pre-commit file executable
chmod +x .git/hooks/pre-commit

Usage

This will work automatically before every commit.

PHP Lint(Syntax check)

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_CodeSniffer is a set of two PHP scripts; the main phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard, and a second phpcbf script to automatically correct coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent.

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

The PHP Coding Standards Fixer (PHP CS Fixer) tool fixes your code to follow standards; whether you want to follow PHP coding standards as defined in the PSR-1, PSR-2, etc., or other community driven ones like the Symfony one.

PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD. PHPMD can be seen as an user friendly frontend application for the raw metrics stream measured by PHP Depend.

phpcpd is a Copy/Paste Detector (CPD) for PHP code.

License

MIT License