Skip to content

Commit

Permalink
Merge pull request #8 from digitalpulp/issue-7
Browse files Browse the repository at this point in the history
Spread helper implementation to all scripts.
  • Loading branch information
FatherShawn authored Apr 22, 2020
2 parents 076e715 + ba45c17 commit f9f30f8
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 137 deletions.
42 changes: 0 additions & 42 deletions hooks.yaml

This file was deleted.

3 changes: 3 additions & 0 deletions pre_commit_hooks/helpers/colors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Regular
txtblk='\033[0;30m' # Black
txtred='\033[0;31m' # Red
txtmag='\033[0;35m' # Magenta
txtgrn='\033[0;32m' # Green
txtylw='\033[0;33m' # Yellow
txtblu='\033[0;34m' # Blue
Expand All @@ -17,6 +18,7 @@ txtwht='\033[0;37m' # White
# Bold
bldblk='\033[1;30m' # Black
bldred='\033[1;31m' # Red
bldmag='\033[1;35m' # Magenta
bldgrn='\033[1;32m' # Green
bldylw='\033[1;33m' # Yellow
bldblu='\033[1;34m' # Blue
Expand All @@ -27,6 +29,7 @@ bldwht='\033[1;37m' # White
# Underline
unkblk='\033[4;30m' # Black
undred='\033[4;31m' # Red
undmag='\033[4;35m' # Magenta
undgrn='\033[4;32m' # Green
undylw='\033[4;33m' # Yellow
undblu='\033[4;34m' # Blue
Expand Down
47 changes: 19 additions & 28 deletions pre_commit_hooks/php-cbf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,35 @@
# Arguments
# - None

# Echo Colors
msg_color_magenta='\e[1;35m'
msg_color_yellow='\e[0;33m'
msg_color_none='\e[0m' # No Color
# Plugin title
title="PHP Code Beautifier and Fixer"

# Possible command names of this tool
local_command="phpcbf.phar"
vendor_command="vendor/bin/phpcbf"
global_command="phpcbf"

# Print a welcome and locate the exec for this tool
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $DIR/helpers/colors.sh
source $DIR/helpers/formatters.sh
source $DIR/helpers/welcome.sh
source $DIR/helpers/locate.sh

# Loop through the list of paths to run PHP Code Beautifier and Fixer against
echo -en "${msg_color_yellow}Begin PHP Code Beautifier and Fixer ...${msg_color_none} \n"
phpcbf_local_exec="phpcbf.phar"
phpcbf_command="php $phpcbf_local_exec"

# Check vendor/bin/phpunit
phpcbf_vendor_command="vendor/bin/phpcbf"
phpcbf_global_command="phpcbf"
if [ -f "$phpcbf_vendor_command" ]; then
phpcbf_command=$phpcbf_vendor_command
else
if hash phpcbf 2>/dev/null; then
phpcbf_command=$phpcbf_global_command
else
if [ -f "$phpcbf_local_exec" ]; then
phpcbf_command=$phpcbf_command
else
echo "No valid PHP Code Beautifier and Fixer executable found! Please have one available as either $phpcbf_vendor_command, $phpcbf_global_command or $phpcbf_local_exec"
exit 1
fi
fi
fi

phpcbf_files_to_check="${@:2}"
phpcbf_args=$1
# Without this escape field, the parameters would break if there was a comma in it
phpcbf_command="$phpcbf_command $phpcbf_args $phpcbf_files_to_check"
phpcbf_command="${exec_command} ${phpcbf_args} ${phpcbf_files_to_check}"

echo "Running command $phpcbf_command"
echo -e "${bldwht}Running command ${txtgrn} $phpcbf_command${txtrst}"
command_result=`eval $phpcbf_command`
if [[ $command_result =~ ERROR ]]
then
echo -en "${msg_color_magenta}Errors detected by PHP Code Beautifier and Fixer ... ${msg_color_none} \n"
hr
echo -en "${bldmag}Errors detected by PHP Code Beautifier and Fixer ... ${txtrst} \n"
hr
echo "$command_result"
exit 1
fi
Expand Down
47 changes: 18 additions & 29 deletions pre_commit_hooks/php-cs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,34 @@
# Arguments
# - None

# Echo Colors
msg_color_magenta='\033[1;35m'
msg_color_yellow='\033[0;33m'
msg_color_none='\033[0m' # No Color
# Plugin title
title="PHP Codesniffer"

# Loop through the list of paths to run php codesniffer against
echo -en "${msg_color_yellow}Begin PHP Codesniffer ...${msg_color_none} \n"
phpcs_local_exec="phpcs.phar"
phpcs_command="php $phpcs_local_exec"
# Possible command names of this tool
local_command="phpcs.phar"
vendor_command="vendor/bin/phpcs"
global_command="phpcs"

# Check vendor/bin/phpunit
phpcs_vendor_command="vendor/bin/phpcs"
phpcs_global_command="phpcs"
if [ -f "$phpcs_vendor_command" ]; then
phpcs_command=$phpcs_vendor_command
else
if hash phpcs 2>/dev/null; then
phpcs_command=$phpcs_global_command
else
if [ -f "$phpcs_local_exec" ]; then
phpcs_command=$phpcs_command
else
echo "No valid PHP Codesniffer executable found! Please have one available as either $phpcs_vendor_command, $phpcs_global_command or $phpcs_local_exec"
exit 1
fi
fi
fi
# Print a welcome and locate the exec for this tool
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $DIR/helpers/colors.sh
source $DIR/helpers/formatters.sh
source $DIR/helpers/welcome.sh
source $DIR/helpers/locate.sh

phpcs_files_to_check="${@:2}"
phpcs_args=$1
phpcs_command="$phpcs_command $phpcs_args $phpcs_files_to_check"
phpcs_command="${exec_command} ${phpcs_args} ${phpcs_files_to_check}"

echo "Running command $phpcs_command"
echo -e "${bldwht}Running command ${txtgrn}$phpcs_command${txtrst}"
command_result=`eval $phpcs_command`
if [[ $command_result =~ ERROR ]]
then
echo -en "${msg_color_magenta}Errors detected by PHP CodeSniffer ... ${msg_color_none} \n"
hr
echo -en "${bldmag}Errors detected by PHP CodeSniffer ... ${txtrst} \n"
hr
echo "$command_result"
exit 1
fi

exit 0
exit 0
24 changes: 15 additions & 9 deletions pre_commit_hooks/php-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ check_args_flag_all='all'
check_args_flag_first='first'
check_all=true

# Echo Colors
msg_color_magenta='\e[1;35m'
msg_color_yellow='\e[0;33m'
msg_color_none='\e[0m' # No Color
# Plugin title
title="PHP Linter"

# Print a welcome and locate the exec for this tool
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $DIR/helpers/colors.sh
source $DIR/helpers/formatters.sh
source $DIR/helpers/welcome.sh

# Where to stop looking for file paths in the argument list
arg_lookup_start=1
Expand All @@ -51,8 +55,6 @@ while getopts ":s:" optname
done

# Loop through the list of paths to run php lint against
echo -en "${msg_color_yellow}Begin PHP Linter ...${msg_color_none} \n"

parse_error_count=0
for path in ${*:$arg_lookup_start}
do
Expand All @@ -62,15 +64,19 @@ do
parse_error_count=$[$parse_error_count +1]
php_errors_found=true
if [ "$check_all" = false ]; then
echo "Stopping at the first file with PHP Parse errors"
hr
echo -e "${txtmag}Stopping at the first file with PHP Parse errors${txtrst}"
hr
exit 1
fi
fi
done;

if [ "$php_errors_found" = true ]; then
echo -en "${msg_color_magenta}$parse_error_count${msg_color_none} ${msg_color_yellow}PHP Parse error(s) were found!${msg_color_none} \n"
hr
echo -en "${bldmag}$parse_error_count${txtrst} ${txtylw}PHP Parse error(s) were found!${txtrst} \n"
hr
exit 1
fi

exit 0
exit 0
46 changes: 17 additions & 29 deletions pre_commit_hooks/php-unit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,29 @@
# Arguments
# - None

# Echo Colors
msg_color_magenta='\e[1;35m'
msg_color_yellow='\e[0;33m'
msg_color_none='\e[0m' # No Color
# Plugin title
title="PHP Unit Task Runner"

# Loop through the list of paths to run php lint against
echo -en "${msg_color_yellow}Begin PHP Unit Task Runner ...${msg_color_none} \n"
# Possible command names of this tool
local_command="phpunit.phar"
vendor_command="vendor/bin/phpunit"
global_command="phpunit"

phpunit_local_exec="phpunit.phar"
phpunit_command="php $phpunit_local_exec"
# Print a welcome and locate the exec for this tool
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $DIR/helpers/colors.sh
source $DIR/helpers/formatters.sh
source $DIR/helpers/welcome.sh
source $DIR/helpers/locate.sh

# Check vendor/bin/phpunit
phpunit_vendor_command="vendor/bin/phpunit"
phpunit_global_command="phpunit"
if [ -f "$phpunit_vendor_command" ]; then
phpunit_command=$phpunit_vendor_command
else
if hash phpunit 2>/dev/null; then
phpunit_command=$phpunit_global_command
else
if [ -f "$phpunit_local_exec" ]; then
phpunit_command=$phpunit_command
else
echo "No valid PHP Unit executable found! Please have one available as either $phpunit_vendor_command, $phpunit_global_command or $phpunit_local_exec"
exit 1
fi
fi
fi

echo "Running command $phpunit_command"
command_result=`eval $phpunit_command`
echo -e "${bldwht}Running command ${txtgrn} ${exec_command}"
command_result=`eval $exec_command`
if [[ $command_result =~ FAILURES ]]
then
hr
echo "Failures detected in unit tests..."
hr
echo "$command_result"
exit 1
fi
exit 0
exit 0

0 comments on commit f9f30f8

Please sign in to comment.