diff --git a/src/Command/CopyCsConfigCommand.php b/src/Command/CopyCsConfigCommand.php index 64f8b9d..8681279 100644 --- a/src/Command/CopyCsConfigCommand.php +++ b/src/Command/CopyCsConfigCommand.php @@ -57,15 +57,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int private function copyConfig(string $destination, string $type, string $template): void { - $modified = @filemtime($destination); - if ($modified && (time() - $modified < 604800)) { - if (!$this->quiet) { - $this->io?->warning("$type config already exists and is less than a week old"); - } - - return; - } - $files = $this->getFinder() ->ignoreDotFiles(false) ->in(__DIR__ . '/../../templates/cs') diff --git a/templates/cs/.php-cs-fixer-8.1.dist.php b/templates/cs/.php-cs-fixer-8.1.dist.php index 013576a..0c7c494 100644 --- a/templates/cs/.php-cs-fixer-8.1.dist.php +++ b/templates/cs/.php-cs-fixer-8.1.dist.php @@ -10,8 +10,12 @@ 'concat_space' => ['spacing' => 'one'], 'php_unit_method_casing' => ['case' => 'camel_case'], 'phpdoc_to_comment' => false, - 'trailing_comma_in_multiline' => ['elements' => ['arrays', 'arguments', 'parameters']], + 'trailing_comma_in_multiline' => ['elements' => ['arrays', 'arguments', 'parameters', 'match']], 'no_unused_imports' => true, + 'heredoc_indentation' => true, + 'ternary_to_null_coalescing' => true, + 'assign_null_coalescing_to_coalesce_equal' => true, + 'single_line_throw' => false, ]) ->setFinder($finder) ; diff --git a/templates/hooks/pre-commit b/templates/hooks/pre-commit index 6f4c55f..503e53c 100755 --- a/templates/hooks/pre-commit +++ b/templates/hooks/pre-commit @@ -24,7 +24,7 @@ scriptPath="$(dirname -- "$thisScript")" make -s copy-cs-config options="--quiet" -hooks="pre-commit-phpcs pre-commit-eslint pre-commit-twig %custom_hooks%" +hooks="pre-commit-phpcs pre-commit-psalm pre-commit-eslint pre-commit-twig %custom_hooks%" for hook in $hooks do diff --git a/templates/hooks/pre-commit-phpcs b/templates/hooks/pre-commit-phpcs index e3eb789..475420b 100755 --- a/templates/hooks/pre-commit-phpcs +++ b/templates/hooks/pre-commit-phpcs @@ -8,6 +8,14 @@ then exit 0 fi +if [ "${CF_COMMIT_PHPCS_AUTOFIX_ENABLED:-0}" == 1 ] +then + # Run fixer and add changes to the commit + make -s phpcs-fix files="${files}" + git add ${files} + exit 0 +fi + # Construct the phpcs command. command=$(echo "make -s phpcs files=\"${files}\"") echo "$command" @@ -36,4 +44,4 @@ then # Exit so you can stage the files and commit again returnCode=1 fi -exit $returnCode +exit $returnCode \ No newline at end of file diff --git a/templates/hooks/pre-commit-psalm b/templates/hooks/pre-commit-psalm new file mode 100755 index 0000000..eaf7645 --- /dev/null +++ b/templates/hooks/pre-commit-psalm @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +if [ "${CF_COMMIT_PSALM_ENABLED:-1}" != 1 ] +then + echo "pre-commit psalm disabled" + exit 0 +fi + +# Grab the staged files +stagedFiles=($(git diff --cached --name-only --diff-filter=AM | grep -e .php$)) +files="${stagedFiles[@]}" +if [ "$files" = '' ] +then + echo "psalm: no php files to check" + exit 0 +fi + +make -s det cmd="vendor/bin/psalm --no-progress --no-cache ${files}" \ No newline at end of file