diff --git a/dev/setup/git/hooks/pre-commit b/dev/setup/git/hooks/pre-commit index 273fa9f620b..9ff94ff4f5d 100644 --- a/dev/setup/git/hooks/pre-commit +++ b/dev/setup/git/hooks/pre-commit @@ -1,13 +1,17 @@ #!/bin/sh -# To install this precommit file: put this file in your local repo in .git/hooks directory and make it executable -# you need to adapt the path to your phpcs install -# if phpcs check fail, then it run phpcbf to fix automaticaly the syntax, and git commit is canceled -# if you have a multiprocessor computer, you can add to the option --parallel=xx -# when running git commit, it first execute this file checking only modified files, so it is faster than running on all files -# To run the fix manually: cd ~/git/dolibarr; phpcbf -s -p -d memory_limit=-1 --extensions=php --colors --tab-width=4 --standard=dev/setup/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true fileordir +# To install this precommit file: put this file in your local repo in .git/hooks directory and make it executable. +# You may need to set th DIRPHPCS to the path to your phpcs install. +# If phpcs check fail and AUTOFIX is set to 1, then it run phpcbf to fix automaticaly the syntax, and git commit is canceled. +# If you have a multiprocessor computer, you can add to the option --parallel=xx +# When running git commit, it first execute this file checking only modified files, so it is faster than running on all files +# To run the fix manually: cd ~/git/dolibarr; phpcbf -s -p -d memory_limit=-1 --extensions=php --colors --tab-width=4 --standard=dev/setup/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true "fileordir" PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"` STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php` +DIRPHPCS="" +AUTOFIX=1 + +echo "Running precommit hook in .git/hooks/pre-commit" 1>&2; # Determine if a file list is passed if [ "$#" -eq 1 ] @@ -20,36 +24,50 @@ then fi SFILES=${SFILES:-$STAGED_FILES_CMD} -echo "Checking PHP Lint..." +echo "Checking PHP Lint with php -l ..." + for FILE in $SFILES do php -l -d display_errors=0 $PROJECT/$FILE - if [ $? != 0 ] + + result1=$? + + if [ "x$result1" != "x0" ] then - echo "Fix the error before commit." + echo "Fix the error before commit." 1>&2; exit 1 fi FILES="$FILES $PROJECT/$FILE" done + if [ "$FILES" != "" ] then echo "Running PHPCS Code Sniffer..." + #~/vendor/bin/phpcs --version #phpcs --standard=PSR2 --encoding=utf-8 -n -p $FILES # Check Dolibarr standard - ~/vendor/bin/phpcs -s -p -d memory_limit=-1 --parallel=2 --extensions=php --colors --tab-width=4 --standard=dev/setup/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES + phpcs -s -p -d memory_limit=-1 --parallel=2 --extensions=php --colors --tab-width=4 --standard=dev/setup/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES # Check your own standard - #~/vendor/bin/phpcs -s -p -d memory_limit=-1 --parallel=2 --extensions=php --colors --tab-width=4 --standard=htdocs/custom/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES + #${DIRPHPCS}phpcs -s -p -d memory_limit=-1 --parallel=2 --extensions=php --colors --tab-width=4 --standard=htdocs/custom/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES + + result2=$? - if [ $? != 0 ] + if [ "x$result2" != "x0" ] then - # fix standard errors - ~/vendor/bin/phpcbf -s -p -d memory_limit=-1 --extensions=php --colors --tab-width=4 --standard=dev/setup/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES - #~/vendor/bin/phpcbf -s -p -d memory_limit=-1 --extensions=php --colors --tab-width=4 --standard=htdocs/custom/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES - echo "Fix the error before commit." - exit 1 + # Fix standard errors + if [ "x$AUTOFIX" != "x0" ] + then + phpcbf -s -p -d memory_limit=-1 --extensions=php --colors --tab-width=4 --standard=dev/setup/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES + #${DIRPHPCS}phpcbf -s -p -d memory_limit=-1 --extensions=php --colors --tab-width=4 --standard=htdocs/custom/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true $FILES + echo "Found some errors in syntax rules. An automatice fix has been applied. Check it before commit." 1>&2; + exit 1 + else + echo "Found some errors in syntax rules. Fix the error(s) before commit." 1>&2; + exit 1 + fi fi fi -exit $? +exit 0 diff --git a/htdocs/product/note.php b/htdocs/product/note.php index e112771fdcd..348d5956588 100644 --- a/htdocs/product/note.php +++ b/htdocs/product/note.php @@ -35,13 +35,12 @@ $langs->load("companies"); $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); -$action = GET PO ST('action','aZ09'); +$action = GETPOST('action', 'aZ09'); // Security check $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : '')); $fieldtype = (!empty($ref) ? 'ref' : 'rowid'); -if ($user->socid) -{ +if ($user->socid) { $socid = $user->socid; } $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);