Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add syntax checker for contributors. #1097

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@ tests/Proxies/*
tests/Hydrators/*
phpunit.xml
vendor/
/bin/
13 changes: 12 additions & 1 deletion composer.json
Expand Up @@ -24,11 +24,22 @@
"doctrine/mongodb": ">=1.1.5,<2.0"
},
"require-dev": {
"symfony/yaml": "~2.3|~3.0"
"symfony/yaml": "~2.3|~3.0",
"squizlabs/php_codesniffer": "~2.0"
},
"suggest": {
"symfony/yaml": "Enables the YAML metadata mapping driver"
},
"scripts": {
"post-install-cmd": [
"bash contrib/setup.sh"
],
"post-update-cmd": [
]
},
"config": {
"bin-dir": "bin"
},
"autoload": {
"psr-0": { "Doctrine\\ODM\\MongoDB": "lib/" }
},
Expand Down
78 changes: 76 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions contrib/pre-commit
@@ -0,0 +1,39 @@
#!/bin/bash
# Pre-commit Git hook.
# Runs PHP CS Fixer on PHP files.
#
# If you absolutely must commit without testing,
# use: git commit --no-verify

# This will check only staged files to be commited.
filenames=($(git diff --staged --name-only HEAD))

# This will set text to red in terminal.
text_red=`tput setaf 1`
# This will set the text to green in terminal.
text_green=`tput setaf 2`
# This will reset the terminal text to normal.
text_reset=`tput sgr0`

numberFilesChanged="${#filenames[@]}"

if [[ $numberFilesChanged > 0 ]];
then
echo "$numberFilesChanged files were changed, running php-cs-fixer"
# PHP CS Fixer.
for i in "${filenames[@]}"
do
if [[ $i == *.php ]];
then
./bin/phpcbf --standard=PSR2 -p -n $i --diff

if [ $? -ne 0 ];
then
# File had some issues. Now it is fine. Add this file to git again.
git add $i
fi
fi
done
fi

echo "${text_green}PHP CS Fixer finished execution successfully.${text_reset}"
7 changes: 7 additions & 0 deletions contrib/setup.sh
@@ -0,0 +1,7 @@
#!/bin/sh

# Copy the pre-commit hook to the current repository hooks directory.
cp contrib/pre-commit .git/hooks/pre-commit

# Add execution permission for pre-commit file.
chmod +x .git/hooks/pre-commit