diff --git a/.git-hooks/pre-commit b/.git-hooks/pre-commit new file mode 100755 index 0000000000..3b692cbeee --- /dev/null +++ b/.git-hooks/pre-commit @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# get bash colors and styles here: +# http://misc.flogisoft.com/bash/tip_colors_and_formatting +style_reset='\e[0m' +style_red='\e[31m' +style_green='\e[32m' +style_bold='\e[1m' +style_underline='\e[4m' +style_dim='\e[2m' + +function __run() #(step, name, cmd) +{ + local output exitcode + + printf "[%s] %-20s" "$1" "$2" + output=$(eval "$3" 2>&1) + exitcode=$? + + if [[ 0 == "$exitcode" || 130 == "$exitcode" ]]; then + echo -e " ${style_green}OK!${style_reset}" + else + echo -e " ${style_red}ERROR!${style_reset}" + echo -e "\n${style_bold}Git commit was interrupted!${style_reset}" + echo -e "${style_underline}$2${style_reset} run failed:" + echo -e "${style_dim}$3${style_reset}${style_bold}$output${style_reset}\n" + echo -e "Fix all the reported issues and try again. Or run commit command with \"--no-verify\" option to skip all configured pre-commit hooks." + exit 1 + fi +} + +php="docker-compose exec -T php php" +internalDir="source/Internal" +testsDir="tests/" + +modified="git diff --cached --name-only --diff-filter=ACM | grep '.php$'" +ecs="${php} vendor/bin/ecs check ${internalDir} ${testsDir} --no-diffs --no-progress-bar" + +echo -e "Running pre-commit hooks:" +__run "1/2" "PHP lint" "${modified} | xargs -r ${php} -l" +__run "2/2" "Easy Coding Standard" "${ecs}" diff --git a/.git-hooks/symlink.sh b/.git-hooks/symlink.sh new file mode 100755 index 0000000000..4a9eb058d1 --- /dev/null +++ b/.git-hooks/symlink.sh @@ -0,0 +1,12 @@ +#!/bin/sh +if [ ! -L .git/hooks ]; +then + echo ".git/hooks is not symlink" + echo "copying .git/hooks to .git/old_hooks" + mv .git/hooks .git/old_hooks + + echo "symlinking ../.git-hooks .git/hooks" + ln -s ../.git-hooks .git/hooks +else + echo ".git/hooks is already a symlink" +fi diff --git a/composer.json b/composer.json index 631a0903ff..dbbe242afc 100644 --- a/composer.json +++ b/composer.json @@ -58,7 +58,8 @@ "phpunit/phpunit": "^11.4", "squizlabs/php_codesniffer": "^3.5.4", "symfony/browser-kit": "^6.4", - "symfony/http-client": "^6.4" + "symfony/http-client": "^6.4", + "symplify/easy-coding-standard": "^12.3" }, "minimum-stability": "dev", "prefer-stable": true, @@ -94,10 +95,12 @@ }, "scripts": { "post-install-cmd": [ - "@oe:ide-helper:generate" + "@oe:ide-helper:generate", + "[ $COMPOSER_DEV_MODE -eq 0 ] || ./.git-hooks/symlink.sh" ], "post-update-cmd": [ - "@oe:ide-helper:generate" + "@oe:ide-helper:generate", + "[ $COMPOSER_DEV_MODE -eq 0 ] || ./.git-hooks/symlink.sh" ], "oe:ide-helper:generate": [ "if [ -f ./vendor/bin/oe-eshop-ide_helper ]; then oe-eshop-ide_helper; fi" diff --git a/ecs.php b/ecs.php new file mode 100644 index 0000000000..cae4c08d80 --- /dev/null +++ b/ecs.php @@ -0,0 +1,63 @@ +withRules([ + BlankLineBetweenImportGroupsFixer::class, + ]) + ->withPreparedSets( + psr12: true, + common: true, + strict: true, + ) + ->withConfiguredRule( + HeaderCommentFixer::class, + [ + 'header' => 'Copyright © OXID eSales AG. All rights reserved. +See LICENSE file for license details.', + 'location' => 'after_open', + 'comment_type' => 'PHPDoc' + ] + ) + ->withConfiguredRule( + ClassAttributesSeparationFixer::class, + [ + 'elements' => [ + 'property' => ClassAttributesSeparationFixer::SPACING_NONE, + 'const' => ClassAttributesSeparationFixer::SPACING_NONE, + ], + ] + ) + ->withConfiguredRule( + OrderedImportsFixer::class, + [ + 'sort_algorithm' => OrderedImportsFixer::SORT_ALPHA, + 'imports_order' => [ + OrderedImportsFixer::IMPORT_TYPE_CLASS, + OrderedImportsFixer::IMPORT_TYPE_FUNCTION, + OrderedImportsFixer::IMPORT_TYPE_CONST, + ] + ] + ) + ->withSkip( + [ + NotOperatorWithSuccessorSpaceFixer::class, + DeclareStrictTypesFixer::class => [ + '*Interface.php', + ] + ], + );