diff --git a/composer.json b/composer.json index f551d644fc4b2341401230f745675bf5acd7ee3f..7a7d7fdde1791e84a764bb5a3720eeb710b902f6 100644 --- a/composer.json +++ b/composer.json @@ -77,8 +77,7 @@ "phpmd/phpmd": "2.6.0", "phpunit/phpunit": "6.5.13", "sebastian/phpcpd": "3.0.1", - "squizlabs/php_codesniffer": "3.4.0", - "exussum12/coverage-checker": "^1.0" + "squizlabs/php_codesniffer": "3.4.0" }, "extra": { "merge-plugin": { diff --git a/composer.lock b/composer.lock index a3e867e8b1a46199234dc1cc6e831d36f4e9d73d..7a97fdfdadc4c54a51bb8df5b5341c22ab81c8fd 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "8912fd5b6c4ad5d520c1a17bbc17f289", + "content-hash": "8f632938475a6265104ca49d4fe4539a", "packages": [ { "name": "ahand/mobileesp", @@ -2987,7 +2987,6 @@ "symfony", "words" ], - "abandoned": "use `EnglishInflector` from the String component instead", "time": "2019-01-01T13:45:19+00:00" }, { @@ -7191,52 +7190,6 @@ ], "time": "2014-09-09T13:34:57+00:00" }, - { - "name": "exussum12/coverage-checker", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/exussum12/coverageChecker.git", - "reference": "495c9cb512cdb057cd2c63e6bda0efee4838bb3a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/exussum12/coverageChecker/zipball/495c9cb512cdb057cd2c63e6bda0efee4838bb3a", - "reference": "495c9cb512cdb057cd2c63e6bda0efee4838bb3a", - "shasum": "" - }, - "require": { - "ext-json": "*", - "ext-xmlreader": "*", - "nikic/php-parser": "^3.1||^4.0", - "php": ">=7.0" - }, - "require-dev": { - "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0" - }, - "bin": [ - "bin/diffFilter" - ], - "type": "library", - "autoload": { - "psr-4": { - "exussum12\\CoverageChecker\\": "src/", - "exussum12\\CoverageChecker\\tests\\": "tests/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Scott Dutton", - "email": "scott@exussum.co.uk" - } - ], - "description": "Allows checking the code coverage of a single pull request", - "time": "2020-10-27T22:49:24+00:00" - }, { "name": "friendsofphp/php-cs-fixer", "version": "v2.14.0", @@ -7437,58 +7390,6 @@ ], "time": "2017-10-19T19:58:43+00:00" }, - { - "name": "nikic/php-parser", - "version": "v4.13.2", - "source": { - "type": "git", - "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "210577fe3cf7badcc5814d99455df46564f3c077" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/210577fe3cf7badcc5814d99455df46564f3c077", - "reference": "210577fe3cf7badcc5814d99455df46564f3c077", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": ">=7.0" - }, - "require-dev": { - "ircmaxell/php-yacc": "^0.0.7", - "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" - }, - "bin": [ - "bin/php-parse" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.9-dev" - } - }, - "autoload": { - "psr-4": { - "PhpParser\\": "lib/PhpParser" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Nikita Popov" - } - ], - "description": "A PHP parser written in PHP", - "keywords": [ - "parser", - "php" - ], - "time": "2021-11-30T19:35:32+00:00" - }, { "name": "pdepend/pdepend", "version": "2.5.2", @@ -8107,7 +8008,6 @@ "keywords": [ "tokenizer" ], - "abandoned": true, "time": "2017-11-27T05:48:46+00:00" }, { @@ -8569,7 +8469,6 @@ ], "description": "FinderFacade is a convenience wrapper for Symfony's Finder component.", "homepage": "https://github.com/sebastianbergmann/finder-facade", - "abandoned": true, "time": "2017-11-18T17:31:49+00:00" }, { @@ -9794,12 +9693,12 @@ "version": "1.4.0", "source": { "type": "git", - "url": "https://github.com/webmozarts/assert.git", + "url": "https://github.com/webmozart/assert.git", "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozarts/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", + "url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9", "shasum": "" }, diff --git a/devops/codecheck/rules/phpcs.xml b/devops/codecheck/rules/phpcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..2582e8367df172cbcd9b47644a796636d0f09e08 --- /dev/null +++ b/devops/codecheck/rules/phpcs.xml @@ -0,0 +1,17 @@ +<?xml version="1.0"?> +<ruleset name="VuFind Coding Standards" namespace="VuFind\PHPCS"> + <description>Coding standards for VuFind.</description> + <file>../module</file> + <exclude-pattern>module/[^/]+/config/*</exclude-pattern> + <exclude-pattern>module/[^/]+/tests/*</exclude-pattern> + <exclude-pattern>/devops/*</exclude-pattern> + <arg name="extensions" value="php"/> + <rule ref="PEAR"> + <exclude name="PEAR.Commenting.FunctionComment.ParamCommentAlignment" /> + </rule> + <rule ref="PEAR.WhiteSpace.ObjectOperatorIndent"> + <properties> + <property name="multilevel" value="true" /> + </properties> + </rule> +</ruleset> diff --git a/devops/codecheck/rules/vufind.php-cs-fixer.php b/devops/codecheck/rules/vufind.php-cs-fixer.php new file mode 100644 index 0000000000000000000000000000000000000000..d55a4188a9735aca2f6f8032e932c3b3dc55081d --- /dev/null +++ b/devops/codecheck/rules/vufind.php-cs-fixer.php @@ -0,0 +1,93 @@ +<?php + /** + * Configuration for VuFind 8 + */ + $finder = new PhpCsFixer\Finder(); + $finder->in(__DIR__ . '/../../../config') + ->in(__DIR__ . '/../../../module') + ->in(__DIR__ . '/../../../public'); + + $rules = [ + 'align_multiline_comment' => true, + 'array_syntax' => ['syntax' => 'short'], + 'binary_operator_spaces' => [ + 'default' => 'single_space', + 'operators' => ['=' => null, '=>' => null], + ], + 'blank_line_after_namespace' => true, + 'braces' => true, + 'cast_spaces' => ['space' => 'none'], + 'class_attributes_separation' => ['elements' => ['method' => 'one', 'property' => 'one']], + 'concat_space' => ['spacing' => 'one'], + 'constant_case' => ['case' => 'lower'], + 'elseif' => true, + 'encoding' => true, + 'ereg_to_preg' => true, + 'full_opening_tag' => true, + 'function_declaration' => true, + 'function_typehint_space' => true, + 'indentation_type' => true, + 'is_null' => true, + 'line_ending' => true, + 'linebreak_after_opening_tag' => true, + 'list_syntax' => ['syntax' => 'short'], + 'lowercase_cast' => true, + 'lowercase_keywords' => true, + 'magic_constant_casing' => true, + 'method_argument_space' => true, + 'native_function_casing' => true, + 'no_blank_lines_after_class_opening' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_blank_lines_before_namespace' => true, + 'no_closing_tag' => true, + 'no_empty_comment' => true, + 'no_empty_phpdoc' => true, + 'no_empty_statement' => true, + 'no_extra_blank_lines' => true, + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_mixed_echo_print' => true, + 'no_singleline_whitespace_before_semicolons' => true, + 'no_spaces_after_function_name' => true, + 'no_spaces_around_offset' => true, + 'no_spaces_inside_parenthesis' => true, + 'no_trailing_whitespace' => true, + 'no_trailing_whitespace_in_comment' => true, + 'no_unneeded_control_parentheses' => true, + 'no_unneeded_curly_braces' => true, + 'no_unused_imports' => true, + 'no_useless_return' => true, + 'no_whitespace_before_comma_in_array' => true, + 'no_whitespace_in_blank_line' => true, + 'non_printable_character' => true, + 'ordered_imports' => true, + 'phpdoc_no_access' => true, + 'php_unit_dedicate_assert_internal_type' => true, + 'php_unit_expectation' => true, + 'php_unit_method_casing' => true, + 'php_unit_mock' => true, + 'php_unit_no_expectation_annotation' => true, + 'pow_to_exponentiation' => true, + 'single_blank_line_at_eof' => true, + 'single_class_element_per_statement' => true, + 'single_import_per_statement' => true, + 'single_line_after_imports' => true, + 'short_scalar_cast' => true, + 'standardize_not_equals' => true, + 'switch_case_semicolon_to_colon' => true, + 'switch_case_space' => true, + 'ternary_operator_spaces' => true, + 'ternary_to_null_coalescing' => true, + 'visibility_required' => true, + ]; + + $cacheDir = __DIR__ . '/../../../data/cache/.php_cs_cache'; + if (!is_dir($cacheDir)) { + mkdir($cacheDir); + } + + $config = new PhpCsFixer\Config(); + return $config->setCacheFile($cacheDir . '/.code.cache') + ->setRiskyAllowed(true) + ->setRules($rules) + ->setFinder($finder); diff --git a/devops/codecheck/rules/vufind_templates.php-cs-fixer.php b/devops/codecheck/rules/vufind_templates.php-cs-fixer.php new file mode 100644 index 0000000000000000000000000000000000000000..ff3070f91609396792e322f563e652fe00ff510b --- /dev/null +++ b/devops/codecheck/rules/vufind_templates.php-cs-fixer.php @@ -0,0 +1,83 @@ +<?php +/** + * Configuration for VuFind 8 + */ +$finder = new PhpCsFixer\Finder(); +$finder->in(__DIR__ . '/../../../themes') + ->name('*.phtml'); + +$rules = [ + 'align_multiline_comment' => true, + 'array_syntax' => ['syntax' => 'short'], + 'binary_operator_spaces' => [ + 'default' => 'single_space', + ], + 'blank_line_after_namespace' => true, + //'braces' => true, // disabled because we don't want to create inconsistent indentation, but useful to normalize control structure spacing + 'cast_spaces' => ['space' => 'none'], + 'class_attributes_separation' => ['elements' => ['method' => 'one', 'property' => 'one']], + 'concat_space' => ['spacing' => 'one'], + 'constant_case' => ['case' => 'lower'], + 'elseif' => true, + 'encoding' => true, + 'ereg_to_preg' => true, + 'full_opening_tag' => true, + 'function_declaration' => true, + 'function_typehint_space' => true, + 'indentation_type' => true, + 'is_null' => true, + 'line_ending' => true, + 'list_syntax' => ['syntax' => 'short'], + 'lowercase_cast' => true, + 'lowercase_keywords' => true, + 'magic_constant_casing' => true, + 'method_argument_space' => true, + 'native_function_casing' => true, + 'no_blank_lines_after_class_opening' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_blank_lines_before_namespace' => true, + 'no_empty_comment' => true, + 'no_empty_phpdoc' => true, + 'no_empty_statement' => true, + 'no_extra_blank_lines' => true, + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_mixed_echo_print' => true, + 'no_singleline_whitespace_before_semicolons' => true, + 'no_spaces_after_function_name' => true, + 'no_spaces_around_offset' => true, + 'no_spaces_inside_parenthesis' => true, + 'no_trailing_whitespace' => true, + 'no_unneeded_control_parentheses' => true, + 'no_unneeded_curly_braces' => true, + 'no_unused_imports' => true, + 'no_useless_return' => true, + 'no_whitespace_before_comma_in_array' => true, + 'no_whitespace_in_blank_line' => true, + 'non_printable_character' => true, + 'ordered_imports' => true, + 'phpdoc_no_access' => true, + 'pow_to_exponentiation' => true, + 'single_blank_line_at_eof' => true, + 'single_class_element_per_statement' => true, + 'single_import_per_statement' => true, + 'single_line_after_imports' => true, + 'short_scalar_cast' => true, + 'standardize_not_equals' => true, + 'switch_case_semicolon_to_colon' => true, + 'switch_case_space' => true, + //'ternary_operator_spaces' => true, // disabled due to bug in php-cs-fixer 2.7.1 + 'ternary_to_null_coalescing' => true, + 'visibility_required' => true, +]; + +$cacheDir = __DIR__ . '/../../../data/cache/.php_cs_cache'; +if (!is_dir($cacheDir)) { + mkdir($cacheDir); +} + +$config = new PhpCsFixer\Config(); +return $config->setCacheFile($cacheDir . '/.template.cache') + ->setRiskyAllowed(true) + ->setRules($rules) + ->setFinder($finder); diff --git a/install-codestylechecker.sh b/install-codestylechecker.sh index 02c158a41dea4e66994f1113479eaa3634e22062..85003b50dd118d0a687fb5a38ff8377e9923d91f 100755 --- a/install-codestylechecker.sh +++ b/install-codestylechecker.sh @@ -4,7 +4,7 @@ red="\e[0;91m" green="\e[0;92m" clean="\e[0m" -if [ -z $1 ] +if [ -z $1 ] then echo -e "\n${red}Nicht genau angegeben was ich tun soll.${clean}\n" echo -e "---------------------------------------------------------------------------" @@ -15,7 +15,7 @@ then exit 1 fi -if [ $(which curl) != "/usr/bin/curl" ] +if [ $(which curl) != "/usr/bin/curl" ] then echo -e "\n${red}Benötigt curl.\n" exit 1 @@ -38,8 +38,12 @@ then curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar curl -OL https://alpha.finc.info/vufind2/logs/alpha/CodeSniffer.conf + curl -OL https://alpha.finc.info/vufind2/logs/alpha/diffFilter.phar + curl -OL https://alpha.finc.info/vufind2/logs/alpha/php-cs-fixer3 chmod +x $HOME/bin/codestylechecker/phpcs.phar + chmod +x $HOME/bin/codestylechecker/diffFilter.phar + chmod +x $HOME/bin/codestylechecker/php-cs-fixer3 echo -e "\n${green}Kopiere Hooks nach ${gitdir}/.git/hooks\n${clean}" @@ -55,6 +59,7 @@ then chmod +x $gitdir/.git/hooks/pre-push echo -e "\n${green}Ready${clean}\n" + echo -e "\n${green}Activate PHP CS Fixer in PHPSorm: https://projekte.ub.uni-leipzig.de/projects/finc-intern/wiki/Code-Quality-Checking_mit_PHPStorm${clean}\n" exit 0 elif [ $1 = "update" ]