diff --git a/.distignore b/.distignore index 80b833e..d784bde 100644 --- a/.distignore +++ b/.distignore @@ -1,23 +1,26 @@ -/.wordpress-org +.distignore +.gitattributes +.gitignore +.phpcs.cache +.phpstan.neon.dist +.phpcs.xml.dist +.phpunit.result.cache +.scrutinizer.yml /.git /.github /.idea +/.wordpress-org /bin /mslsselect /reports /tests -.distignore -.gitattributes -.gitignore -.scrutinizer.yml Changelog.md +README.md composer.json composer.lock mslsselect.zip -package.json package-lock.json +package.json phpdoc.xml phpstan.neon phpunit.xml -README.md - diff --git a/.gitignore b/.gitignore index 5f61134..df0cf92 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ +.phpcs.cache +.phpunit.result.cache composer.lock phpunit.xml.bak -.phpunit.result.cache .idea/ vendor/ coverage/ diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist new file mode 100644 index 0000000..4d0b4c1 --- /dev/null +++ b/.phpcs.xml.dist @@ -0,0 +1,26 @@ + + + PHPCS MslsMenu configuration + + bin/* + tests/* + vendor/* + + + + + + + + + + + + + + + + + + + diff --git a/phpstan.neon b/.phpstan.neon.dist similarity index 100% rename from phpstan.neon rename to .phpstan.neon.dist diff --git a/MslsSelect.php b/MslsSelect.php index 5e993de..1b71bc7 100644 --- a/MslsSelect.php +++ b/MslsSelect.php @@ -5,6 +5,7 @@ * @copyright Copyright (C) 2011-2024, Dennis Ploetner, re@lloc.de * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 or later * @wordpress-plugin + * @package mslsselect * * Plugin Name: MslsSelect * Requires Plugins: multisite-language-switcher @@ -60,12 +61,12 @@ public function __construct() { */ public static function init(): self { if ( ! is_admin() ) { - add_action( 'wp_enqueue_scripts', [ __CLASS__, 'enqueue_scripts' ] ); - add_filter( 'msls_output_get_tags', [ __CLASS__, 'get_tags' ] ); - add_filter( 'msls_output_get', [ __CLASS__, 'output_get' ], 10, 3 ); + add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) ); + add_filter( 'msls_output_get_tags', array( __CLASS__, 'get_tags' ) ); + add_filter( 'msls_output_get', array( __CLASS__, 'output_get' ), 10, 3 ); } - return new self; + return new self(); } /** @@ -91,7 +92,7 @@ public static function enqueue_scripts(): void { * * @param string $url * @param object $link - * @param bool $current + * @param bool $current * * @return string */ @@ -105,20 +106,22 @@ public static function output_get( string $url, $link, bool $current ): string { * @return array */ public static function get_tags(): array { - return [ + return array( 'before_item' => '', 'after_item' => '', 'before_output' => '', - ]; + ); } - } // @codeCoverageIgnoreStart if ( function_exists( 'add_action' ) ) { - add_action( 'plugins_loaded', function () { - MslsSelect::init(); - } ); + add_action( + 'plugins_loaded', + function () { + MslsSelect::init(); + } + ); } // @codeCoverageIgnoreEnd diff --git a/bin/githooks/pre-commit b/bin/githooks/pre-commit new file mode 100644 index 0000000..9458370 --- /dev/null +++ b/bin/githooks/pre-commit @@ -0,0 +1,22 @@ +#!/bin/bash + +echo "" +echo "phpcbf pre commit hook start" + +PHPCBF="vendor/bin/phpcbf" + +# check if phpcbf is installed as a composer dependency +if [ -x "$PHPCBF" ]; then + # gets a list of all staged but not deleted php-files + CHANGED_FILES=$(git diff --cached --name-only --diff-filter=ACMRTUXB HEAD | grep '\.php$') + + if [ -n "$CHANGED_FILES" ]; then + # runs phpcbf on the changed files + "$PHPCBF" -w $CHANGED_FILES + # adds the changed files to staging again + git add $CHANGED_FILES + fi +fi + +echo "phpcbf pre commit hook finish" +echo "" diff --git a/composer.json b/composer.json index 5c6b539..f1a8a7b 100644 --- a/composer.json +++ b/composer.json @@ -18,21 +18,33 @@ "brain/monkey": "2.*", "phpstan/phpstan": "^1.8", "szepeviktor/phpstan-wordpress": "^1.1", - "phpstan/extension-installer": "^1.1" + "phpstan/extension-installer": "^1.1", + "wp-coding-standards/wpcs": "^3.0" }, "scripts": { "test": "vendor/bin/phpunit", "coverage": "php -d xdebug.mode=coverage vendor/bin/phpunit --coverage-html coverage", - "analyze": "vendor/bin/phpstan analyze", + "phpstan": "vendor/bin/phpstan analyze", "git-release": "bin/git-release.sh", "build": [ "@git-release" + ], + "githooks": [ + "if [ -e bin/githooks/pre-commit ]; then cp bin/githooks/pre-commit ./.git/hooks/; fi", + "if [ -e .git/hooks/pre-commit ]; then chmod 0755 .git/hooks/pre-commit; fi" + ], + "post-install-cmd": [ + "@githooks" + ], + "post-update-cmd": [ + "@githooks" ] }, "config": { "allow-plugins": { "composer/installers": true, - "phpstan/extension-installer": true + "phpstan/extension-installer": true, + "dealerdirect/phpcodesniffer-composer-installer": true } } } diff --git a/readme.txt b/readme.txt index 8b5b030..dd44615 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Contributors: realloc Donate link: http://www.greenpeace.org/international/ Tags: multilingual, multisite, language, switcher, select Requires at least: 5.6 -Tested up to: 6.7 +Tested up to: 6.8 Requires PHP: 7.4 Stable tag: 2.3.4 License: GPLv2 or later