From e83cf5938481ee1ffb70a17f88fcf984c6f51638 Mon Sep 17 00:00:00 2001 From: Dennis Ploetner Date: Sun, 12 Oct 2025 20:57:55 +0200 Subject: [PATCH 1/3] Chore finished --- .distignore | 19 +++++++++++-------- .gitignore | 3 ++- .phpcs.xml.dist | 26 ++++++++++++++++++++++++++ phpstan.neon => .phpstan.neon.dist | 0 MslsSelect.php | 25 ++++++++++++++----------- bin/githooks/pre-commit | 28 ++++++++++++++++++++++++++++ composer.json | 18 +++++++++++++++--- 7 files changed, 96 insertions(+), 23 deletions(-) create mode 100644 .phpcs.xml.dist rename phpstan.neon => .phpstan.neon.dist (100%) create mode 100644 bin/githooks/pre-commit 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..fd4d359 --- /dev/null +++ b/bin/githooks/pre-commit @@ -0,0 +1,28 @@ +#!/bin/bash + +echo "" +echo "phpcbf pre commit hook start" + +PHP_CS_FIXER="vendor/bin/phpcbf" +HAS_PHP_CS_FIXER=false + +# check if php-cs-fixer is installed as a composer dependency +if [ -x "$PHP_CS_FIXER" ]; then + HAS_PHP_CS_FIXER=true +fi + +if $HAS_PHP_CS_FIXER; 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 [ ! -z "${CHANGED_FILES}" ]; then + # runs phpcbf on the changed files + vendor/bin/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 } } } From c9eb8072d62f6fd7e0836e380a1bf1454b1679c2 Mon Sep 17 00:00:00 2001 From: Dennis Ploetner Date: Sun, 12 Oct 2025 21:00:56 +0200 Subject: [PATCH 2/3] Update bin/githooks/pre-commit Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- bin/githooks/pre-commit | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/bin/githooks/pre-commit b/bin/githooks/pre-commit index fd4d359..9458370 100644 --- a/bin/githooks/pre-commit +++ b/bin/githooks/pre-commit @@ -3,24 +3,18 @@ echo "" echo "phpcbf pre commit hook start" -PHP_CS_FIXER="vendor/bin/phpcbf" -HAS_PHP_CS_FIXER=false - -# check if php-cs-fixer is installed as a composer dependency -if [ -x "$PHP_CS_FIXER" ]; then - HAS_PHP_CS_FIXER=true -fi - -if $HAS_PHP_CS_FIXER; then +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 [ ! -z "${CHANGED_FILES}" ]; then + if [ -n "$CHANGED_FILES" ]; then # runs phpcbf on the changed files - vendor/bin/phpcbf -w ${CHANGED_FILES} + "$PHPCBF" -w $CHANGED_FILES # adds the changed files to staging again - git add ${CHANGED_FILES} + git add $CHANGED_FILES fi fi From 562a92a858ea29992e69cea1ba3baaa7112921eb Mon Sep 17 00:00:00 2001 From: Dennis Ploetner Date: Sun, 12 Oct 2025 21:05:17 +0200 Subject: [PATCH 3/3] Chore finished --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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