From d39191ebe54d557edb5d883db112f4bf1e9e3a17 Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Mon, 6 Apr 2026 13:49:05 -0400 Subject: [PATCH 1/6] PHPCS: Declare visibility on InsertPostHandler methods used in hooks --- inc/class-insert-post-handler.php | 4 ++-- inc/class-users-controller.php | 2 +- inc/cli/class-migrate-command.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/inc/class-insert-post-handler.php b/inc/class-insert-post-handler.php index 59d9fa99..d565d14d 100644 --- a/inc/class-insert-post-handler.php +++ b/inc/class-insert-post-handler.php @@ -33,7 +33,7 @@ class InsertPostHandler { * to wp_insert_post(). * @return mixed[] An array of slashed, sanitized, and processed post data. */ - function filter_wp_insert_post_data( array $data, array $postarr, $unsanitized_postarr ) : array { + public function filter_wp_insert_post_data( array $data, array $postarr, $unsanitized_postarr ) : array { // Make sure the unsanitized post array is actually an array. Core sometimes passes it as a WP_Post object. $this->postarr = (array) $unsanitized_postarr; @@ -47,7 +47,7 @@ function filter_wp_insert_post_data( array $data, array $postarr, $unsanitized_p * @param WP_Post $post Post object. * @param bool $update Whether this is an existing post being updated. */ - function action_wp_insert_post( int $post_ID, WP_Post $post, bool $update ) : void { + public function action_wp_insert_post( int $post_ID, WP_Post $post, bool $update ) : void { $unsanitized_postarr = $this->postarr; $this->postarr = []; diff --git a/inc/class-users-controller.php b/inc/class-users-controller.php index 712ceed4..f1c4dedc 100644 --- a/inc/class-users-controller.php +++ b/inc/class-users-controller.php @@ -135,7 +135,7 @@ public function get_items( $request ) { * @param \WP_REST_Request $request The current request. * @return mixed[] Array of arguments for WP_User_Query. */ - function filter_rest_user_query( array $prepared_args, \WP_REST_Request $request ) : array { + public function filter_rest_user_query( array $prepared_args, \WP_REST_Request $request ) : array { unset( $prepared_args['has_published_posts'] ); return $prepared_args; diff --git a/inc/cli/class-migrate-command.php b/inc/cli/class-migrate-command.php index cc86bcce..f9fe1ad8 100644 --- a/inc/cli/class-migrate-command.php +++ b/inc/cli/class-migrate-command.php @@ -188,7 +188,7 @@ public function wp_authors( $args, $assoc_args ) : void { * @param array $args CLI arguments * @param array $assoc_args CLI arguments */ - function ppa( $args, $assoc_args ) : void { + public function ppa( $args, $assoc_args ) : void { if ( ! taxonomy_exists( 'author' ) ) { // register the `author` taxonomy so that we can query for PPA author terms. register_taxonomy( 'author', 'post' ); From 80957167a5ffabbc8d7c8570e82837e769458f78 Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Mon, 6 Apr 2026 13:51:50 -0400 Subject: [PATCH 2/6] Upgrade to prerelease v2 of HMCS --- composer.json | 9 +- composer.lock | 393 ++++++++++++++++++++++++++++++++++++++++--------- phpcs.xml.dist | 10 +- 3 files changed, 336 insertions(+), 76 deletions(-) diff --git a/composer.json b/composer.json index 32ae219d..2fc27feb 100644 --- a/composer.json +++ b/composer.json @@ -11,19 +11,24 @@ "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "0.7.0", "ergebnis/composer-normalize": "^2", - "humanmade/coding-standards": "1.1.1", + "humanmade/coding-standards": "dev-upgrade-wpcs", "php-stubs/wordpress-stubs": "^5.5", "phpcompatibility/phpcompatibility-wp": "2.1.0", "phpstan/phpstan": "0.12.57", "phpunit/phpunit": "^9.5.20", "roots/wordpress": "~6.6.0", - "squizlabs/php_codesniffer": "3.5.8", "szepeviktor/phpstan-wordpress": "0.7.1", "vlucas/phpdotenv": "^3", "wp-cli/db-command": "^2", "wp-phpunit/wp-phpunit": "~6.6.0", "yoast/phpunit-polyfills": "^1.0" }, + "repositories": { + "humanmade/coding-standards": { + "type": "git", + "url": "https://github.com/humanmade/coding-standards" + } + }, "config": { "allow-plugins": { "composer/installers": true, diff --git a/composer.lock b/composer.lock index d29882dd..cb73baf1 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": "62cbbe60f560435cdcd03d65b5448679", + "content-hash": "ac27ef853c1982af09cae5ac6f0d19e0", "packages": [ { "name": "composer/installers", @@ -190,30 +190,32 @@ "packages-dev": [ { "name": "automattic/vipwpcs", - "version": "2.0.0", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/Automattic/VIP-Coding-Standards.git", - "reference": "fc02f491dc9f51da7c32941ac579f70b9ed300c5" + "reference": "1b8960ebff9ea3eb482258a906ece4d1ee1e25fd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Automattic/VIP-Coding-Standards/zipball/fc02f491dc9f51da7c32941ac579f70b9ed300c5", - "reference": "fc02f491dc9f51da7c32941ac579f70b9ed300c5", + "url": "https://api.github.com/repos/Automattic/VIP-Coding-Standards/zipball/1b8960ebff9ea3eb482258a906ece4d1ee1e25fd", + "reference": "1b8960ebff9ea3eb482258a906ece4d1ee1e25fd", "shasum": "" }, "require": { - "php": ">=5.6", - "squizlabs/php_codesniffer": "^3.3.1", - "wp-coding-standards/wpcs": "^2.1" + "php": ">=5.4", + "phpcsstandards/phpcsextra": "^1.1.0", + "phpcsstandards/phpcsutils": "^1.0.8", + "sirbrillig/phpcs-variable-analysis": "^2.11.17", + "squizlabs/php_codesniffer": "^3.7.2", + "wp-coding-standards/wpcs": "^3.0" }, "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.5", + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", "phpcompatibility/php-compatibility": "^9", - "phpunit/phpunit": "^5 || ^6 || ^7" - }, - "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." + "phpcsstandards/phpcsdevtools": "^1.0", + "phpunit/phpunit": "^4 || ^5 || ^6 || ^7" }, "type": "phpcodesniffer-standard", "notification-url": "https://packagist.org/downloads/", @@ -230,6 +232,7 @@ "keywords": [ "phpcs", "standards", + "static analysis", "wordpress" ], "support": { @@ -237,7 +240,7 @@ "source": "https://github.com/Automattic/VIP-Coding-Standards", "wiki": "https://github.com/Automattic/VIP-Coding-Standards/wiki" }, - "time": "2019-07-12T08:47:36+00:00" + "time": "2023-09-05T11:01:05+00:00" }, { "name": "dealerdirect/phpcodesniffer-composer-installer", @@ -840,41 +843,35 @@ }, { "name": "humanmade/coding-standards", - "version": "v1.1.1", + "version": "dev-upgrade-wpcs", "source": { "type": "git", - "url": "https://github.com/humanmade/coding-standards.git", - "reference": "841d51064c492b8c9ec5210bbfff38f63cee3243" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/humanmade/coding-standards/zipball/841d51064c492b8c9ec5210bbfff38f63cee3243", - "reference": "841d51064c492b8c9ec5210bbfff38f63cee3243", - "shasum": "" + "url": "https://github.com/humanmade/coding-standards", + "reference": "a13a172c6d3b73c7388322d57eecc8d7a50a56b1" }, "require": { - "automattic/vipwpcs": "2.0.0", + "automattic/vipwpcs": "~3.0.0", "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", "fig-r/psr2r-sniffer": "^0.5.0", "php": ">=7.1", "phpcompatibility/phpcompatibility-wp": "^2.0.0", - "squizlabs/php_codesniffer": "~3.5.0", - "wp-coding-standards/wpcs": "2.2.1" + "squizlabs/php_codesniffer": "~3.5", + "wp-coding-standards/wpcs": "~3.0.0" }, "require-dev": { - "phpunit/phpunit": "^5.7" + "phpunit/phpunit": "^7" }, "type": "phpcodesniffer-standard", - "notification-url": "https://packagist.org/downloads/", + "scripts": { + "test": [ + "phpunit" + ] + }, "license": [ "GPL-2.0-or-later" ], "description": "Human Made Coding Standards", - "support": { - "issues": "https://github.com/humanmade/coding-standards/issues", - "source": "https://github.com/humanmade/coding-standards/tree/v1.1.1" - }, - "time": "2020-10-27T14:25:16+00:00" + "time": "2025-09-19T19:48:05+00:00" }, { "name": "justinrainbow/json-schema", @@ -1398,16 +1395,16 @@ }, { "name": "phpcompatibility/phpcompatibility-paragonie", - "version": "1.3.3", + "version": "1.3.4", "source": { "type": "git", "url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git", - "reference": "293975b465e0e709b571cbf0c957c6c0a7b9a2ac" + "reference": "244d7b04fc4bc2117c15f5abe23eb933b5f02bbf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/293975b465e0e709b571cbf0c957c6c0a7b9a2ac", - "reference": "293975b465e0e709b571cbf0c957c6c0a7b9a2ac", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/244d7b04fc4bc2117c15f5abe23eb933b5f02bbf", + "reference": "244d7b04fc4bc2117c15f5abe23eb933b5f02bbf", "shasum": "" }, "require": { @@ -1464,9 +1461,13 @@ { "url": "https://opencollective.com/php_codesniffer", "type": "open_collective" + }, + { + "url": "https://thanks.dev/u/gh/phpcompatibility", + "type": "thanks_dev" } ], - "time": "2024-04-24T21:30:46+00:00" + "time": "2025-09-19T17:43:28+00:00" }, { "name": "phpcompatibility/phpcompatibility-wp", @@ -1522,6 +1523,181 @@ }, "time": "2019-08-28T14:22:28+00:00" }, + { + "name": "phpcsstandards/phpcsextra", + "version": "1.5.0", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSExtra.git", + "reference": "b598aa890815b8df16363271b659d73280129101" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/b598aa890815b8df16363271b659d73280129101", + "reference": "b598aa890815b8df16363271b659d73280129101", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "phpcsstandards/phpcsutils": "^1.2.0", + "squizlabs/php_codesniffer": "^3.13.5 || ^4.0.1" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.4.0", + "phpcsstandards/phpcsdevcs": "^1.2.0", + "phpcsstandards/phpcsdevtools": "^1.2.1", + "phpunit/phpunit": "^4.5 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSExtra/graphs/contributors" + } + ], + "description": "A collection of sniffs and standards for use with PHP_CodeSniffer.", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHPCSExtra/issues", + "security": "https://github.com/PHPCSStandards/PHPCSExtra/security/policy", + "source": "https://github.com/PHPCSStandards/PHPCSExtra" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + }, + { + "url": "https://thanks.dev/u/gh/phpcsstandards", + "type": "thanks_dev" + } + ], + "time": "2025-11-12T23:06:57+00:00" + }, + { + "name": "phpcsstandards/phpcsutils", + "version": "1.2.2", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSUtils.git", + "reference": "c216317e96c8b3f5932808f9b0f1f7a14e3bbf55" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/c216317e96c8b3f5932808f9b0f1f7a14e3bbf55", + "reference": "c216317e96c8b3f5932808f9b0f1f7a14e3bbf55", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^3.13.5 || ^4.0.1" + }, + "require-dev": { + "ext-filter": "*", + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.4.0", + "phpcsstandards/phpcsdevcs": "^1.2.0", + "yoast/phpunit-polyfills": "^1.1.0 || ^2.0.0 || ^3.0.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "autoload": { + "classmap": [ + "PHPCSUtils/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSUtils/graphs/contributors" + } + ], + "description": "A suite of utility functions for use with PHP_CodeSniffer", + "homepage": "https://phpcsutils.com/", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "phpcs3", + "phpcs4", + "standards", + "static analysis", + "tokens", + "utility" + ], + "support": { + "docs": "https://phpcsutils.com/", + "issues": "https://github.com/PHPCSStandards/PHPCSUtils/issues", + "security": "https://github.com/PHPCSStandards/PHPCSUtils/security/policy", + "source": "https://github.com/PHPCSStandards/PHPCSUtils" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + }, + { + "url": "https://thanks.dev/u/gh/phpcsstandards", + "type": "thanks_dev" + } + ], + "time": "2025-12-08T14:27:58+00:00" + }, { "name": "phpoption/phpoption", "version": "1.9.3", @@ -3226,18 +3402,74 @@ ], "time": "2020-09-28T06:39:44+00:00" }, + { + "name": "sirbrillig/phpcs-variable-analysis", + "version": "v2.13.0", + "source": { + "type": "git", + "url": "https://github.com/sirbrillig/phpcs-variable-analysis.git", + "reference": "a15e970b8a0bf64cfa5e86d941f5e6b08855f369" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sirbrillig/phpcs-variable-analysis/zipball/a15e970b8a0bf64cfa5e86d941f5e6b08855f369", + "reference": "a15e970b8a0bf64cfa5e86d941f5e6b08855f369", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "squizlabs/php_codesniffer": "^3.5.7 || ^4.0.0" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || ^1.0", + "phpstan/phpstan": "^1.7 || ^2.0", + "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.5 || ^7.0 || ^8.0 || ^9.0 || ^10.5.32 || ^11.3.3", + "vimeo/psalm": "^0.2 || ^0.3 || ^1.1 || ^4.24 || ^5.0 || ^6.0 || ^7.0" + }, + "type": "phpcodesniffer-standard", + "autoload": { + "psr-4": { + "VariableAnalysis\\": "VariableAnalysis/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Sam Graham", + "email": "php-codesniffer-variableanalysis@illusori.co.uk" + }, + { + "name": "Payton Swick", + "email": "payton@foolord.com" + } + ], + "description": "A PHPCS sniff to detect problems with variables.", + "keywords": [ + "phpcs", + "static analysis" + ], + "support": { + "issues": "https://github.com/sirbrillig/phpcs-variable-analysis/issues", + "source": "https://github.com/sirbrillig/phpcs-variable-analysis", + "wiki": "https://github.com/sirbrillig/phpcs-variable-analysis/wiki" + }, + "time": "2025-09-30T22:22:48+00:00" + }, { "name": "squizlabs/php_codesniffer", - "version": "3.5.8", + "version": "3.13.5", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "9d583721a7157ee997f235f327de038e7ea6dac4" + "reference": "0ca86845ce43291e8f5692c7356fccf3bcf02bf4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/9d583721a7157ee997f235f327de038e7ea6dac4", - "reference": "9d583721a7157ee997f235f327de038e7ea6dac4", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/0ca86845ce43291e8f5692c7356fccf3bcf02bf4", + "reference": "0ca86845ce43291e8f5692c7356fccf3bcf02bf4", "shasum": "" }, "require": { @@ -3247,18 +3479,13 @@ "php": ">=5.4.0" }, "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" }, "bin": [ - "bin/phpcs", - "bin/phpcbf" + "bin/phpcbf", + "bin/phpcs" ], "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.x-dev" - } - }, "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" @@ -3266,19 +3493,29 @@ "authors": [ { "name": "Greg Sherwood", - "role": "lead" + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" } ], "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", "keywords": [ "phpcs", - "standards" + "standards", + "static analysis" ], "support": { - "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", - "source": "https://github.com/squizlabs/PHP_CodeSniffer", - "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" }, "funding": [ { @@ -3292,9 +3529,13 @@ { "url": "https://opencollective.com/php_codesniffer", "type": "open_collective" + }, + { + "url": "https://thanks.dev/u/gh/phpcsstandards", + "type": "thanks_dev" } ], - "time": "2020-10-23T02:01:07+00:00" + "time": "2025-11-04T16:30:35+00:00" }, { "name": "symfony/deprecation-contracts", @@ -4112,29 +4353,38 @@ }, { "name": "wp-coding-standards/wpcs", - "version": "2.2.1", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", - "reference": "b5a453203114cc2284b1a614c4953456fbe4f546" + "reference": "b4caf9689f1a0e4a4c632679a44e638c1c67aff1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/b5a453203114cc2284b1a614c4953456fbe4f546", - "reference": "b5a453203114cc2284b1a614c4953456fbe4f546", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/b4caf9689f1a0e4a4c632679a44e638c1c67aff1", + "reference": "b4caf9689f1a0e4a4c632679a44e638c1c67aff1", "shasum": "" }, "require": { + "ext-filter": "*", + "ext-libxml": "*", + "ext-tokenizer": "*", + "ext-xmlreader": "*", "php": ">=5.4", - "squizlabs/php_codesniffer": "^3.3.1" + "phpcsstandards/phpcsextra": "^1.1.0", + "phpcsstandards/phpcsutils": "^1.0.8", + "squizlabs/php_codesniffer": "^3.7.2" }, "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || ^0.6", + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", "phpcompatibility/php-compatibility": "^9.0", + "phpcsstandards/phpcsdevtools": "^1.2.0", "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.6 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." + "ext-iconv": "For improved results", + "ext-mbstring": "For improved results" }, "type": "phpcodesniffer-standard", "notification-url": "https://packagist.org/downloads/", @@ -4151,6 +4401,7 @@ "keywords": [ "phpcs", "standards", + "static analysis", "wordpress" ], "support": { @@ -4158,7 +4409,13 @@ "source": "https://github.com/WordPress/WordPress-Coding-Standards", "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki" }, - "time": "2020-02-04T02:52:06+00:00" + "funding": [ + { + "url": "https://opencollective.com/thewpcc/contribute/wp-php-63406", + "type": "custom" + } + ], + "time": "2023-09-14T07:06:09+00:00" }, { "name": "wp-phpunit/wp-phpunit", @@ -4274,13 +4531,15 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "humanmade/coding-standards": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { "php": ">=7.2" }, - "platform-dev": [], + "platform-dev": {}, "platform-overrides": { "php": "7.4" }, diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 460c2656..fdf93771 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -34,13 +34,9 @@ - - - - - - - + + + From 7de28976a6b6b099c18b39e130a3724e2da3760e Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Mon, 6 Apr 2026 13:54:24 -0400 Subject: [PATCH 3/6] phpcbf --- inc/admin.php | 10 +-- inc/class-insert-post-handler.php | 4 +- inc/class-users-controller.php | 4 +- inc/cli/class-migrate-command.php | 16 ++--- inc/cli/namespace.php | 2 +- inc/namespace.php | 62 +++++++++---------- inc/taxonomy.php | 4 +- inc/template.php | 18 +++--- tests/phpunit/includes/bootstrap.php | 4 +- tests/phpunit/includes/email-testcase.php | 4 +- tests/phpunit/includes/feed-testcase.php | 2 +- tests/phpunit/includes/restapi-testcase.php | 8 +-- tests/phpunit/includes/testcase.php | 2 +- tests/phpunit/test-archive.php | 4 +- tests/phpunit/test-capabilities.php | 32 +++++----- tests/phpunit/test-cli.php | 6 +- tests/phpunit/test-emails.php | 7 +-- tests/phpunit/test-feed-rss2.php | 2 +- tests/phpunit/test-multisite.php | 1 - tests/phpunit/test-plugin.php | 6 +- tests/phpunit/test-post-saving.php | 14 ++--- tests/phpunit/test-rest-api-post-property.php | 20 +++--- tests/phpunit/test-rest-api-user-endpoint.php | 40 ++++++------ tests/phpunit/test-template.php | 52 ++++++++-------- tests/phpunit/test-wp-query.php | 12 ++-- 25 files changed, 167 insertions(+), 169 deletions(-) diff --git a/inc/admin.php b/inc/admin.php index 8971699d..7d1d0609 100644 --- a/inc/admin.php +++ b/inc/admin.php @@ -24,7 +24,7 @@ /** * Bootstraps the main actions and filters. */ -function bootstrap() : void { +function bootstrap(): void { // Actions. add_action( 'admin_init', __NAMESPACE__ . '\\init_admin_cols', 99 ); add_action( 'user_profile_update_errors', __NAMESPACE__ . '\\remove_required_fields_errors', 10, 3 ); @@ -38,7 +38,7 @@ function bootstrap() : void { * @param stdClass $user User object (passed by reference). * @return void */ -function remove_required_fields_errors( WP_Error $errors, bool $update, stdClass $user ) : void { +function remove_required_fields_errors( WP_Error $errors, bool $update, stdClass $user ): void { if ( $user->role !== GUEST_ROLE ) { return; } @@ -55,7 +55,7 @@ function remove_required_fields_errors( WP_Error $errors, bool $update, stdClass /** * Fires as an admin screen or script is being initialized. */ -function init_admin_cols() : void { +function init_admin_cols(): void { foreach ( get_supported_post_types() as $post_type ) { add_filter( "manage_{$post_type}_posts_columns", __NAMESPACE__ . '\\filter_post_columns' ); add_action( "manage_{$post_type}_posts_custom_column", __NAMESPACE__ . '\\action_author_column', 10, 2 ); @@ -68,7 +68,7 @@ function init_admin_cols() : void { * @param string $column_name The name of the column to display. * @param int $post_id The current post ID. */ -function action_author_column( string $column_name, int $post_id ) : void { +function action_author_column( string $column_name, int $post_id ): void { if ( COLUMN_NAME !== $column_name ) { return; } @@ -105,7 +105,7 @@ function action_author_column( string $column_name, int $post_id ) : void { * @param string[] $post_columns An associative array of column headings. * @return string[] An associative array of column headings. */ -function filter_post_columns( array $post_columns ) : array { +function filter_post_columns( array $post_columns ): array { $new_columns = []; foreach ( $post_columns as $key => $value ) { diff --git a/inc/class-insert-post-handler.php b/inc/class-insert-post-handler.php index d565d14d..96f491d3 100644 --- a/inc/class-insert-post-handler.php +++ b/inc/class-insert-post-handler.php @@ -33,7 +33,7 @@ class InsertPostHandler { * to wp_insert_post(). * @return mixed[] An array of slashed, sanitized, and processed post data. */ - public function filter_wp_insert_post_data( array $data, array $postarr, $unsanitized_postarr ) : array { + public function filter_wp_insert_post_data( array $data, array $postarr, $unsanitized_postarr ): array { // Make sure the unsanitized post array is actually an array. Core sometimes passes it as a WP_Post object. $this->postarr = (array) $unsanitized_postarr; @@ -47,7 +47,7 @@ public function filter_wp_insert_post_data( array $data, array $postarr, $unsani * @param WP_Post $post Post object. * @param bool $update Whether this is an existing post being updated. */ - public function action_wp_insert_post( int $post_ID, WP_Post $post, bool $update ) : void { + public function action_wp_insert_post( int $post_ID, WP_Post $post, bool $update ): void { $unsanitized_postarr = $this->postarr; $this->postarr = []; diff --git a/inc/class-users-controller.php b/inc/class-users-controller.php index f1c4dedc..91497b20 100644 --- a/inc/class-users-controller.php +++ b/inc/class-users-controller.php @@ -135,7 +135,7 @@ public function get_items( $request ) { * @param \WP_REST_Request $request The current request. * @return mixed[] Array of arguments for WP_User_Query. */ - public function filter_rest_user_query( array $prepared_args, \WP_REST_Request $request ) : array { + public function filter_rest_user_query( array $prepared_args, \WP_REST_Request $request ): array { unset( $prepared_args['has_published_posts'] ); return $prepared_args; @@ -208,7 +208,7 @@ public function create_item( $request ) { * @type WP_Error $errors WP_Error object containing any errors found. * } */ - add_filter( 'wpmu_validate_user_signup', function( array $result ) : array { + add_filter( 'wpmu_validate_user_signup', function ( array $result ): array { /** @var WP_Error $errors */ $errors = $result['errors']; $errors->remove( 'user_email' ); diff --git a/inc/cli/class-migrate-command.php b/inc/cli/class-migrate-command.php index f9fe1ad8..821990e8 100644 --- a/inc/cli/class-migrate-command.php +++ b/inc/cli/class-migrate-command.php @@ -65,7 +65,7 @@ class Migrate_Command extends WP_CLI_Command { * @param array $args CLI arguments * @param array $assoc_args CLI arguments */ - public function wp_authors( $args, $assoc_args ) : void { + public function wp_authors( $args, $assoc_args ): void { $posts_per_page = 100; $paged = 1; $count = 0; @@ -128,7 +128,7 @@ public function wp_authors( $args, $assoc_args ) : void { \Authorship\set_authors( $post, [ intval( $post->post_author ) ] ); } - $count++; + ++$count; }//end foreach // Avoid memory exhaustion issues. @@ -138,7 +138,7 @@ public function wp_authors( $args, $assoc_args ) : void { WP_CLI::line( sprintf( 'Processed %d posts, pausing for a breath...', $count ) ); sleep( 2 ); - $paged++; + ++$paged; } while ( count( $posts ) ); if ( true === $dry_run ) { @@ -188,7 +188,7 @@ public function wp_authors( $args, $assoc_args ) : void { * @param array $args CLI arguments * @param array $assoc_args CLI arguments */ - public function ppa( $args, $assoc_args ) : void { + public function ppa( $args, $assoc_args ): void { if ( ! taxonomy_exists( 'author' ) ) { // register the `author` taxonomy so that we can query for PPA author terms. register_taxonomy( 'author', 'post' ); @@ -288,7 +288,7 @@ public function ppa( $args, $assoc_args ) : void { \Authorship\set_authors( $post, $new_authors ); } - $count++; + ++$count; }//end foreach // Avoid memory exhaustion issues. @@ -298,7 +298,7 @@ public function ppa( $args, $assoc_args ) : void { WP_CLI::line( sprintf( 'Processed %d posts, pausing for a breath...', $count ) ); sleep( 2 ); - $paged++; + ++$paged; } while ( count( $posts ) ); if ( true === $dry_run ) { @@ -317,7 +317,7 @@ public function ppa( $args, $assoc_args ) : void { * * @return integer a user ID for this term, or -1 if not resolvable */ - private function get_ppa_user_id( WP_Term $ppa_author, bool $create_users = false ) : int { + private function get_ppa_user_id( WP_Term $ppa_author, bool $create_users = false ): int { /** * We need to get the user for Authorship so check if a * user is already mapped in PPA. @@ -379,7 +379,7 @@ private function get_ppa_user_id( WP_Term $ppa_author, bool $create_users = fals * * @see https://github.com/Automattic/vip-go-mu-plugins/blob/master/vip-helpers/vip-caching.php#L733-L747 */ - private function reset_local_object_cache() : void { + private function reset_local_object_cache(): void { /** * @var WP_Object_Cache */ diff --git a/inc/cli/namespace.php b/inc/cli/namespace.php index 5d5697e7..5f8a3188 100644 --- a/inc/cli/namespace.php +++ b/inc/cli/namespace.php @@ -16,6 +16,6 @@ * * @return void */ -function bootstrap() : void { +function bootstrap(): void { WP_CLI::add_command( 'authorship migrate', __NAMESPACE__ . '\\Migrate_Command' ); } diff --git a/inc/namespace.php b/inc/namespace.php index f327cb50..aaa37838 100644 --- a/inc/namespace.php +++ b/inc/namespace.php @@ -36,7 +36,7 @@ /** * Bootstraps the main actions and filters. */ -function bootstrap() : void { +function bootstrap(): void { $insert_post_handler = new InsertPostHandler(); // Actions. @@ -65,7 +65,7 @@ function bootstrap() : void { * * @return string[] List of post types to support. */ -function get_supported_post_types() : array { +function get_supported_post_types(): array { $post_types = get_post_types_by_support( 'author' ); /** @@ -82,7 +82,7 @@ function get_supported_post_types() : array { * @param string $post_type Post type to check. * @return boolean */ -function is_post_type_supported( string $post_type ) : bool { +function is_post_type_supported( string $post_type ): bool { return in_array( $post_type, get_supported_post_types(), true ); } @@ -92,7 +92,7 @@ function is_post_type_supported( string $post_type ) : bool { * @param string|null $display_name The author's display name. * @return string|null The author's display name. */ -function filter_the_author_for_rss( ?string $display_name ) : ?string { +function filter_the_author_for_rss( ?string $display_name ): ?string { if ( ! is_feed( 'rss2' ) ) { return $display_name; } @@ -115,7 +115,7 @@ function filter_the_author_for_rss( ?string $display_name ) : ?string { * @param mixed[] $args The context for the cap, typically with the object ID as the first element. * @return string[] Array of the user's capabilities. */ -function filter_map_meta_cap_for_editing( array $caps, string $cap, int $user_id, array $args ) : array { +function filter_map_meta_cap_for_editing( array $caps, string $cap, int $user_id, array $args ): array { $concerns = [ 'delete_post', 'delete_page', @@ -237,7 +237,7 @@ function filter_map_meta_cap_for_editing( array $caps, string $cap, int $user_id * @param WP_User $user Concerned user object. * @return bool[] Array of concerned user's capabilities. */ -function filter_user_has_cap( array $user_caps, array $required_caps, array $args, WP_User $user ) : array { +function filter_user_has_cap( array $user_caps, array $required_caps, array $args, WP_User $user ): array { $cap = $args[0]; switch ( $cap ) { @@ -285,7 +285,7 @@ function filter_user_has_cap( array $user_caps, array $required_caps, array $arg * * @param WP $wp Current WordPress environment instance. */ -function action_wp( WP $wp ) : void { +function action_wp( WP $wp ): void { if ( is_author() ) { $GLOBALS['authordata'] = get_userdata( get_query_var( 'author' ) ); } @@ -294,7 +294,7 @@ function action_wp( WP $wp ) : void { /** * Fires after WordPress has finished loading but before any headers are sent. */ -function register_roles_and_caps() : void { +function register_roles_and_caps(): void { add_role( GUEST_ROLE, __( 'Guest Author', 'authorship' ), [] ); } @@ -339,12 +339,12 @@ function filter_rest_request_after_callbacks( $result, array $handler, WP_REST_R * * @param WP_REST_Server $server Server object. */ -function register_rest_api_fields( WP_REST_Server $server ) : void { +function register_rest_api_fields( WP_REST_Server $server ): void { $post_types = get_supported_post_types(); array_walk( $post_types, __NAMESPACE__ . '\\register_rest_api_field' ); - $users_controller = new Users_Controller; + $users_controller = new Users_Controller(); $users_controller->register_routes(); } @@ -357,7 +357,7 @@ function register_rest_api_fields( WP_REST_Server $server ) : void { * @param string $post_type The post type name. * @return WP_Error|null Null if the validation passes, `WP_Error` instance otherwise. */ -function validate_authors( $authors, WP_REST_Request $request, string $param, string $post_type ) :? WP_Error { +function validate_authors( $authors, WP_REST_Request $request, string $param, string $post_type ): ?WP_Error { $schema_validation = rest_validate_request_arg( $authors, $request, $param ); if ( is_wp_error( $schema_validation ) ) { @@ -402,24 +402,24 @@ function validate_authors( $authors, WP_REST_Request $request, string $param, st * * @param string $post_type The post type name. */ -function register_rest_api_field( string $post_type ) : void { - $validate_callback = function( $authors, WP_REST_Request $request, string $param ) use ( $post_type ) :? WP_Error { +function register_rest_api_field( string $post_type ): void { + $validate_callback = function ( $authors, WP_REST_Request $request, string $param ) use ( $post_type ): ?WP_Error { return validate_authors( $authors, $request, $param, $post_type ); }; register_rest_field( $post_type, REST_PARAM, [ - 'get_callback' => function( array $post ) : array { + 'get_callback' => function ( array $post ): array { $post = get_post( $post['id'] ); if ( ! $post ) { return []; } - return array_map( function( WP_User $user ) : int { + return array_map( function ( WP_User $user ): int { return $user->ID; }, get_authors( $post ) ); }, - 'update_callback' => function( $value, WP_Post $post, string $field, WP_REST_Request $request, string $post_type ) :? WP_Error { + 'update_callback' => function ( $value, WP_Post $post, string $field, WP_REST_Request $request, string $post_type ): ?WP_Error { try { set_authors( $post, wp_parse_id_list( $value ) ); } catch ( Exception $e ) { @@ -458,7 +458,7 @@ function register_rest_api_field( string $post_type ) : void { * @param WP_REST_Request $request Request object. * @return WP_REST_Response The response object. */ -function rest_prepare_post( WP_REST_Response $response, WP_Post $post, WP_REST_Request $request ) : WP_REST_Response { +function rest_prepare_post( WP_REST_Response $response, WP_Post $post, WP_REST_Request $request ): WP_REST_Response { $links = $response->get_links(); if ( isset( $links['https://api.w.org/action-assign-author'] ) ) { @@ -475,7 +475,7 @@ function rest_prepare_post( WP_REST_Response $response, WP_Post $post, WP_REST_R * @param array[] $additional Additional CURIEs to register with the API. * @return array[] Additional CURIEs to register with the API. */ -function filter_rest_response_link_curies( array $additional ) : array { +function filter_rest_response_link_curies( array $additional ): array { $additional[] = [ 'name' => REST_PARAM, 'href' => REST_CURIE_TEMPLATE, @@ -488,7 +488,7 @@ function filter_rest_response_link_curies( array $additional ) : array { /** * Fires after block assets have been enqueued for the editing interface. */ -function enqueue_assets() : void { +function enqueue_assets(): void { /** @var WP_Post|null */ $post = get_post(); @@ -503,7 +503,7 @@ function enqueue_assets() : void { /** * Enqueues the JS and CSS assets for the author selection control. */ -function enqueue_assets_for_post() : void { +function enqueue_assets_for_post(): void { $manifest = plugin_dir_path( __DIR__ ) . 'build/asset-manifest.json'; enqueue_asset( @@ -538,7 +538,7 @@ function enqueue_assets_for_post() : void { * * @param WP_Post $post The post being edited. */ -function preload_author_data( WP_Post $post ) : void { +function preload_author_data( WP_Post $post ): void { $authors = get_authors( $post ); if ( empty( $authors ) ) { @@ -547,7 +547,7 @@ function preload_author_data( WP_Post $post ) : void { ]; } - $authors = array_map( function( WP_User $user ) { + $authors = array_map( function ( WP_User $user ) { $avatar = get_avatar_url( $user->ID ); return [ @@ -574,7 +574,7 @@ function preload_author_data( WP_Post $post ) : void { * * @param WP_Query $query The WP_Query instance. */ -function action_pre_get_posts( WP_Query $query ) : void { +function action_pre_get_posts( WP_Query $query ): void { $post_type = $query->get( 'post_type' ); if ( empty( $post_type ) ) { @@ -632,7 +632,7 @@ function action_pre_get_posts( WP_Query $query ) : void { } elseif ( ! empty( $stored_values['author__in'] ) ) { $user_ids = array_map( 'intval', $stored_values['author__in'] ); } elseif ( ! empty( $stored_values['author__not_in'] ) ) { - $user_ids = array_map( function( int $id ) : int { + $user_ids = array_map( function ( int $id ): int { return $id * -1; }, array_map( 'intval', $stored_values['author__not_in'] ) ); } @@ -665,7 +665,7 @@ function action_pre_get_posts( WP_Query $query ) : void { * @param WP_Post[]|null $posts Array of post objects. Passed by reference. * @param WP_Query $query The WP_Query instance. */ - add_filter( 'posts_pre_query', function( ?array $posts, WP_Query $query ) use ( &$stored_values, $user_ids ) : ?array { + add_filter( 'posts_pre_query', function ( ?array $posts, WP_Query $query ) use ( &$stored_values, $user_ids ): ?array { if ( empty( $stored_values ) ) { return $posts; } @@ -694,7 +694,7 @@ function action_pre_get_posts( WP_Query $query ) : void { * @param int $comment_id Comment ID. * @return string[] List of email addresses to notify for comment moderation. */ -function filter_comment_moderation_recipients( array $emails, int $comment_id ) : array { +function filter_comment_moderation_recipients( array $emails, int $comment_id ): array { /** @var \WP_Comment */ $comment = get_comment( $comment_id ); $post_id = (int) $comment->comment_post_ID; @@ -711,11 +711,11 @@ function filter_comment_moderation_recipients( array $emails, int $comment_id ) $authors = get_authors( $post ); - $moderators = array_filter( $authors, function( WP_User $user ) use ( $comment ) : bool { + $moderators = array_filter( $authors, function ( WP_User $user ) use ( $comment ): bool { return user_can( $user->ID, 'edit_comment', $comment->comment_ID ); } ); - $additional_emails = array_filter( array_map( function( WP_User $user ) : string { + $additional_emails = array_filter( array_map( function ( WP_User $user ): string { return $user->user_email; }, $moderators ) ); @@ -729,7 +729,7 @@ function filter_comment_moderation_recipients( array $emails, int $comment_id ) * @param int $comment_id The comment ID. * @return string[] An array of email addresses to receive a comment notification. */ -function filter_comment_notification_recipients( array $emails, int $comment_id ) : array { +function filter_comment_notification_recipients( array $emails, int $comment_id ): array { /** @var \WP_Comment */ $comment = get_comment( $comment_id ); $post_id = (int) $comment->comment_post_ID; @@ -747,7 +747,7 @@ function filter_comment_notification_recipients( array $emails, int $comment_id $authors = get_authors( $post ); /** @var string[] */ - $additional_emails = array_filter( array_map( function( WP_User $user ) : string { + $additional_emails = array_filter( array_map( function ( WP_User $user ): string { return $user->user_email; }, $authors ) ); @@ -763,7 +763,7 @@ function filter_comment_notification_recipients( array $emails, int $comment_id * @param array $options Options. * @return array Filtered options. */ -function hide_quickedit_authors( array $options ) : array { +function hide_quickedit_authors( array $options ): array { $options['hide_if_only_one_author'] = true; $options['include'] = [ 0 ]; return $options; diff --git a/inc/taxonomy.php b/inc/taxonomy.php index 8898354a..ebdf1f5e 100644 --- a/inc/taxonomy.php +++ b/inc/taxonomy.php @@ -16,7 +16,7 @@ /** * Registers the taxonomy that creates a connection between posts and users. */ -function init_taxonomy() : void { +function init_taxonomy(): void { $post_types = get_supported_post_types(); register_taxonomy( @@ -92,7 +92,7 @@ function init_taxonomy() : void { * @param string[] $views An array of available list table views. * @return string[] An array of available list table views. */ - add_filter( "views_edit-{$post_type}", function( array $views ) use ( $post_type, $text, $user_id ) : array { + add_filter( "views_edit-{$post_type}", function ( array $views ) use ( $post_type, $text, $user_id ): array { if ( ! $text ) { unset( $views['mine'] ); diff --git a/inc/template.php b/inc/template.php index f1335c2e..2a768b70 100644 --- a/inc/template.php +++ b/inc/template.php @@ -20,7 +20,7 @@ * @param WP_Post $post The post object. * @return int[] Array of user IDs. */ -function get_author_ids( WP_Post $post ) : array { +function get_author_ids( WP_Post $post ): array { if ( ! is_post_type_supported( $post->post_type ) ) { if ( post_type_supports( $post->post_type, 'author' ) ) { return [ intval( $post->post_author ) ]; @@ -34,7 +34,7 @@ function get_author_ids( WP_Post $post ) : array { return []; } - return array_map( function ( WP_Term $term ) : int { + return array_map( function ( WP_Term $term ): int { return intval( $term->slug ); }, $authors ); } @@ -45,7 +45,7 @@ function get_author_ids( WP_Post $post ) : array { * @param WP_Post $post The post object. * @return WP_User[] Array of user objects. */ -function get_authors( WP_Post $post ) : array { +function get_authors( WP_Post $post ): array { $author_ids = get_author_ids( $post ); if ( empty( $author_ids ) ) { return []; @@ -72,7 +72,7 @@ function get_authors( WP_Post $post ) : array { * @param WP_Post $post The post object. * @return string List of the names of the authors. */ -function get_author_names( WP_Post $post ) : string { +function get_author_names( WP_Post $post ): string { $authors = get_authors( $post ); return implode( ', ', array_column( $authors, 'display_name' ) ); @@ -89,7 +89,7 @@ function get_author_names( WP_Post $post ) : string { * @param WP_Post $post The post object. * @return string List of the names of the authors. */ -function get_author_names_sentence( WP_Post $post ) : string { +function get_author_names_sentence( WP_Post $post ): string { $authors = get_authors( $post ); if ( empty( $authors ) ) { @@ -116,14 +116,14 @@ function get_author_names_sentence( WP_Post $post ) : string { * @param WP_Post $post The post object. * @return string List of the names of the authors. */ -function get_author_names_list( WP_Post $post ) : string { +function get_author_names_list( WP_Post $post ): string { $authors = get_authors( $post ); if ( empty( $authors ) ) { return ''; } - $list = array_reduce( $authors, function( string $carry, WP_User $author ) { + $list = array_reduce( $authors, function ( string $carry, WP_User $author ) { return "{$carry}\n\t" . sprintf( '
  • %2$s
  • ', esc_url( get_author_posts_url( $author->ID ) ), @@ -147,7 +147,7 @@ function get_author_names_list( WP_Post $post ) : string { * @throws Exception If any of the users do not exist. * @return WP_User[] Array of user objects. */ -function set_authors( WP_Post $post, array $authors ) : array { +function set_authors( WP_Post $post, array $authors ): array { if ( ! is_post_type_supported( $post->post_type ) ) { throw new Exception( __( 'This post type does not support authorship.', 'authorship' ) ); } @@ -184,7 +184,7 @@ function set_authors( WP_Post $post, array $authors ) : array { * @param WP_Post $post The post object. * @return bool Whether the user is an attributed author of the post. */ -function user_is_author( WP_User $user, WP_Post $post ) : bool { +function user_is_author( WP_User $user, WP_Post $post ): bool { if ( ! is_post_type_supported( $post->post_type ) ) { return ( intval( $post->post_author ) === $user->ID ); } diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index e804f731..41532a55 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -10,7 +10,7 @@ namespace Authorship; $_plugin_dir = getcwd(); -$_env_dir = dirname( dirname( __DIR__ ) ); +$_env_dir = dirname( __DIR__, 2 ); require_once $_plugin_dir . '/vendor/autoload.php'; @@ -23,7 +23,7 @@ require_once $_tests_dir . '/includes/functions.php'; -tests_add_filter( 'muplugins_loaded', function() use ( $_plugin_dir ) : void { +tests_add_filter( 'muplugins_loaded', function () use ( $_plugin_dir ): void { require_once $_plugin_dir . '/plugin.php'; } ); diff --git a/tests/phpunit/includes/email-testcase.php b/tests/phpunit/includes/email-testcase.php index f1f019c1..807b7c3a 100644 --- a/tests/phpunit/includes/email-testcase.php +++ b/tests/phpunit/includes/email-testcase.php @@ -20,13 +20,13 @@ abstract class EmailTestCase extends TestCase { */ protected $mailer = null; - public function setUp() : void { + public function setUp(): void { parent::setUp(); reset_phpmailer_instance(); $this->mailer = tests_retrieve_phpmailer_instance(); } - public function tearDown() : void { + public function tearDown(): void { $this->mailer = null; reset_phpmailer_instance(); parent::tearDown(); diff --git a/tests/phpunit/includes/feed-testcase.php b/tests/phpunit/includes/feed-testcase.php index 0f6411b5..675b535b 100644 --- a/tests/phpunit/includes/feed-testcase.php +++ b/tests/phpunit/includes/feed-testcase.php @@ -19,7 +19,7 @@ abstract class FeedTestCase extends TestCase { * @param string $url The URL to visit, eg. `/?feed=rss2`. * @return mixed[] The feed output as an array. */ - public function go_to_feed( string $url ) : array { + public function go_to_feed( string $url ): array { $this->go_to( $url ); ob_start(); diff --git a/tests/phpunit/includes/restapi-testcase.php b/tests/phpunit/includes/restapi-testcase.php index e4798c1d..e4a77b61 100644 --- a/tests/phpunit/includes/restapi-testcase.php +++ b/tests/phpunit/includes/restapi-testcase.php @@ -16,20 +16,20 @@ * REST API test class for the plugin. */ abstract class RESTAPITestCase extends TestCase { - public function setUp() : void { + public function setUp(): void { parent::setUp(); rest_get_server(); } - public function tearDown() : void { + public function tearDown(): void { parent::tearDown(); global $wp_rest_server; $wp_rest_server = null; } - protected static function get_message( WP_REST_REsponse $response ) : string { + protected static function get_message( WP_REST_REsponse $response ): string { if ( $response->is_error() ) { /** @var \WP_Error $error */ $error = $response->as_error(); @@ -51,7 +51,7 @@ protected static function get_message( WP_REST_REsponse $response ) : string { return ''; } - protected static function rest_do_request( WP_REST_Request $request ) : WP_REST_Response { + protected static function rest_do_request( WP_REST_Request $request ): WP_REST_Response { $response = rest_do_request( $request ); return $response; diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index 68a7d4b1..55111446 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.php @@ -48,7 +48,7 @@ public static function wpSetUpBeforeClass( \WP_UnitTest_Factory $factory ) { } } - public function setUp() : void { + public function setUp(): void { parent::setUp(); $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); diff --git a/tests/phpunit/test-archive.php b/tests/phpunit/test-archive.php index 60befc35..af568f1f 100644 --- a/tests/phpunit/test-archive.php +++ b/tests/phpunit/test-archive.php @@ -12,7 +12,7 @@ use const Authorship\POSTS_PARAM; class TestArchive extends TestCase { - public function testAuthorArchiveQueryIsCorrect() : void { + public function testAuthorArchiveQueryIsCorrect(): void { $factory = self::factory()->post; // Attributed to Editor, owned by Admin. @@ -42,7 +42,7 @@ public function testAuthorArchiveQueryIsCorrect() : void { $this->assertSame( self::$users['editor']->ID, $authordata->ID ); } - public function testAuthorArchiveTitleIsCorrect() : void { + public function testAuthorArchiveTitleIsCorrect(): void { $factory = self::factory()->post; // Attributed to Editor, owned by Admin. diff --git a/tests/phpunit/test-capabilities.php b/tests/phpunit/test-capabilities.php index ee37308b..a093f75a 100644 --- a/tests/phpunit/test-capabilities.php +++ b/tests/phpunit/test-capabilities.php @@ -23,7 +23,7 @@ class TestCapabilities extends TestCase { * @param string $role Role name * @param mixed[] $caps Caps */ - public function testUserCanManageDraftPostTheyAreAttributedTo( string $role, array $caps ) : void { + public function testUserCanManageDraftPostTheyAreAttributedTo( string $role, array $caps ): void { $user_id = self::$users[ $role ]->ID; $status = 'draft'; @@ -48,7 +48,7 @@ public function testUserCanManageDraftPostTheyAreAttributedTo( string $role, arr * @param string $role Role name * @param mixed[] $caps Caps */ - public function testUserCanManagePublishedPostTheyAreAttributedTo( string $role, array $caps ) : void { + public function testUserCanManagePublishedPostTheyAreAttributedTo( string $role, array $caps ): void { $user_id = self::$users[ $role ]->ID; $status = 'publish'; @@ -73,7 +73,7 @@ public function testUserCanManagePublishedPostTheyAreAttributedTo( string $role, * @param string $role Role name * @param mixed[] $caps Caps */ - public function testUserCanManageScheduledPostTheyAreAttributedTo( string $role, array $caps ) : void { + public function testUserCanManageScheduledPostTheyAreAttributedTo( string $role, array $caps ): void { $user_id = self::$users[ $role ]->ID; $status = 'future'; @@ -100,7 +100,7 @@ public function testUserCanManageScheduledPostTheyAreAttributedTo( string $role, * @param string $role Role name * @param mixed[] $caps Caps */ - public function testUserCanManagePendingPostTheyAreAttributedTo( string $role, array $caps ) : void { + public function testUserCanManagePendingPostTheyAreAttributedTo( string $role, array $caps ): void { $user_id = self::$users[ $role ]->ID; $status = 'pending'; @@ -125,7 +125,7 @@ public function testUserCanManagePendingPostTheyAreAttributedTo( string $role, a * @param string $role Role name * @param mixed[] $caps Caps */ - public function testUserCanManageTrashedPostTheyAreAttributedTo( string $role, array $caps ) : void { + public function testUserCanManageTrashedPostTheyAreAttributedTo( string $role, array $caps ): void { $user_id = self::$users[ $role ]->ID; $status = 'trash'; @@ -151,7 +151,7 @@ public function testUserCanManageTrashedPostTheyAreAttributedTo( string $role, a * @param string $role Role name * @param mixed[] $caps Caps */ - public function testUserCanManagePrivatePostTheyAreAttributedTo( string $role, array $caps ) : void { + public function testUserCanManagePrivatePostTheyAreAttributedTo( string $role, array $caps ): void { $user_id = self::$users[ $role ]->ID; $status = 'private'; @@ -176,7 +176,7 @@ public function testUserCanManagePrivatePostTheyAreAttributedTo( string $role, a * @param string $role Role name * @param mixed[] $caps Caps */ - public function testUserCanManagePublishedPostTheyAreOwnerOfButNotAttributedTo( string $role, array $caps ) : void { + public function testUserCanManagePublishedPostTheyAreOwnerOfButNotAttributedTo( string $role, array $caps ): void { $user_id = self::$users[ $role ]->ID; $status = 'publish'; @@ -201,7 +201,7 @@ public function testUserCanManagePublishedPostTheyAreOwnerOfButNotAttributedTo( * @param string $role Role name * @param mixed[] $caps Caps */ - public function testUserCannotManagePublishedPostTheyAreNotAttributedTo( string $role, array $caps ) : void { + public function testUserCannotManagePublishedPostTheyAreNotAttributedTo( string $role, array $caps ): void { $user_id = self::$users[ $role ]->ID; $status = 'publish_not_mine'; @@ -223,7 +223,7 @@ public function testUserCannotManagePublishedPostTheyAreNotAttributedTo( string * @param string $role Role name * @param mixed[] $caps Caps */ - public function testUserCannotManageNonExistentPost( string $role, array $caps ) : void { + public function testUserCannotManageNonExistentPost( string $role, array $caps ): void { $user_id = self::$users[ $role ]->ID; $post_id = 1; @@ -240,7 +240,7 @@ public function testUserCannotManageNonExistentPost( string $role, array $caps ) * @param string $role Role name * @param mixed[] $caps Caps */ - public function testDefaultCustomCapMappingIsCorrect( string $role, array $caps ) : void { + public function testDefaultCustomCapMappingIsCorrect( string $role, array $caps ): void { $user_id = self::$users[ $role ]->ID; $this->assertSame( $caps['create_guest_authors'], user_can( $user_id, 'create_guest_authors' ) ); @@ -253,7 +253,7 @@ public function testDefaultCustomCapMappingIsCorrect( string $role, array $caps * @param string $role Role name * @param mixed[] $caps Caps */ - public function testGuestAuthorCreationCanBeGranted( string $role, array $caps ) : void { + public function testGuestAuthorCreationCanBeGranted( string $role, array $caps ): void { $user_id = self::$users[ $role ]->ID; self::$users[ $role ]->add_cap( 'create_guest_authors', true ); @@ -267,7 +267,7 @@ public function testGuestAuthorCreationCanBeGranted( string $role, array $caps ) * @param string $role Role name * @param mixed[] $caps Caps */ - public function testGuestAuthorCreationCanBeDenied( string $role, array $caps ) : void { + public function testGuestAuthorCreationCanBeDenied( string $role, array $caps ): void { $user_id = self::$users[ $role ]->ID; self::$users[ $role ]->add_cap( 'create_guest_authors', false ); @@ -281,7 +281,7 @@ public function testGuestAuthorCreationCanBeDenied( string $role, array $caps ) * @param string $role Role name * @param mixed[] $caps Caps */ - public function testGuestPostAttributionCanBeGranted( string $role, array $caps ) : void { + public function testGuestPostAttributionCanBeGranted( string $role, array $caps ): void { $user_id = self::$users[ $role ]->ID; self::$users[ $role ]->add_cap( 'attribute_post_type', true ); @@ -295,7 +295,7 @@ public function testGuestPostAttributionCanBeGranted( string $role, array $caps * @param string $role Role name * @param mixed[] $caps Caps */ - public function testGuestPostAttributionCanBeDenied( string $role, array $caps ) : void { + public function testGuestPostAttributionCanBeDenied( string $role, array $caps ): void { $user_id = self::$users[ $role ]->ID; self::$users[ $role ]->add_cap( 'attribute_post_type', false ); @@ -306,7 +306,7 @@ public function testGuestPostAttributionCanBeDenied( string $role, array $caps ) /** * @return mixed[] */ - public function dataRolesAndPostCaps() : array { + public function dataRolesAndPostCaps(): array { return [ [ 'editor', @@ -504,7 +504,7 @@ public function dataRolesAndPostCaps() : array { /** * @return mixed[] */ - public function dataRolesAndCustomCaps() : array { + public function dataRolesAndCustomCaps(): array { return [ [ 'admin', diff --git a/tests/phpunit/test-cli.php b/tests/phpunit/test-cli.php index 42f73922..a4a89324 100644 --- a/tests/phpunit/test-cli.php +++ b/tests/phpunit/test-cli.php @@ -21,7 +21,7 @@ public function set_up() { CLI\bootstrap(); } - public function testMigratePostTypePost() : void { + public function testMigratePostTypePost(): void { $factory = self::factory()->post; // Post. Owned by editor, attributed to nobody. @@ -36,7 +36,7 @@ public function testMigratePostTypePost() : void { $authorship_authors = \Authorship\get_authors( $post1 ); $this->assertCount( 0, $authorship_authors ); - $command = new CLI\Migrate_Command; + $command = new CLI\Migrate_Command(); $command->wp_authors( [], [ 'dry-run' => false, 'post-type' => 'post', // Note, have to set default values manually. @@ -48,7 +48,7 @@ public function testMigratePostTypePost() : void { $this->assertSame( self::$users['editor']->ID, $authorship_authors[0]->ID ); } - public function testMigratePostTypePage() : void { + public function testMigratePostTypePage(): void { $factory = self::factory()->post; // Page. Owned by editor, attributed to nobody. diff --git a/tests/phpunit/test-emails.php b/tests/phpunit/test-emails.php index 03af91c7..31aaaa3f 100644 --- a/tests/phpunit/test-emails.php +++ b/tests/phpunit/test-emails.php @@ -13,7 +13,7 @@ use const Authorship\POSTS_PARAM; class TestEmails extends EmailTestCase { - public function testCommentModerationEmailIsSentToUsersWhoCanModerateIt() : void { + public function testCommentModerationEmailIsSentToUsersWhoCanModerateIt(): void { // Attributed to one user of each role: $post_id = self::factory()->post->create( [ 'post_author' => self::$users['editor']->ID, @@ -43,7 +43,7 @@ public function testCommentModerationEmailIsSentToUsersWhoCanModerateIt() : void $this->assertSame( $expected, $actual ); } - public function testCommentModerationEmailDoesNotDuplicateRecipients() : void { + public function testCommentModerationEmailDoesNotDuplicateRecipients(): void { // Attributed to the site admin: $post_id = self::factory()->post->create( [ 'post_author' => 1, @@ -72,7 +72,7 @@ public function testCommentModerationEmailDoesNotDuplicateRecipients() : void { $this->assertSame( $expected, $actual ); } - public function testCommentNotificationEmailIsSentToAllAttributedAuthors() : void { + public function testCommentNotificationEmailIsSentToAllAttributedAuthors(): void { // Attributed to one user of each role: $post_id = self::factory()->post->create( [ 'post_author' => self::$users['editor']->ID, @@ -104,5 +104,4 @@ public function testCommentNotificationEmailIsSentToAllAttributedAuthors() : voi $this->assertSame( $expected, $actual ); } - } diff --git a/tests/phpunit/test-feed-rss2.php b/tests/phpunit/test-feed-rss2.php index c2f0b6b5..2f91bbca 100644 --- a/tests/phpunit/test-feed-rss2.php +++ b/tests/phpunit/test-feed-rss2.php @@ -12,7 +12,7 @@ use const Authorship\POSTS_PARAM; class TestRSS2 extends FeedTestCase { - public function testMultipleAuthorNamesAreListed() : void { + public function testMultipleAuthorNamesAreListed(): void { $factory = self::factory()->post; // Attributed to Editor and Author, owned by Admin. diff --git a/tests/phpunit/test-multisite.php b/tests/phpunit/test-multisite.php index 6ab46e2c..34492b6f 100644 --- a/tests/phpunit/test-multisite.php +++ b/tests/phpunit/test-multisite.php @@ -91,5 +91,4 @@ public function testSuperAdminWithNoRoleOnSite() { restore_current_blog(); } - } diff --git a/tests/phpunit/test-plugin.php b/tests/phpunit/test-plugin.php index 91ea6c18..5880a6bc 100644 --- a/tests/phpunit/test-plugin.php +++ b/tests/phpunit/test-plugin.php @@ -10,8 +10,8 @@ namespace Authorship\Tests; class TestPlugin extends TestCase { - public function testReadmeIsUpToDate() : void { - $file = dirname( dirname( __DIR__ ) ) . '/README.md'; + public function testReadmeIsUpToDate(): void { + $file = dirname( __DIR__, 2 ) . '/README.md'; if ( ! is_file( $file ) ) { $this->fail( 'No readme file present.' ); @@ -22,7 +22,7 @@ public function testReadmeIsUpToDate() : void { preg_match( '|Stable tag:(.*)|i', $file_contents, $stable_tag ); $stable_version = trim( trim( $stable_tag[1], '*' ) ); - $plugin_data = get_plugin_data( dirname( dirname( __DIR__ ) ) . '/plugin.php' ); + $plugin_data = get_plugin_data( dirname( __DIR__, 2 ) . '/plugin.php' ); $this->assertSame( $stable_version, $plugin_data['Version'] ); } diff --git a/tests/phpunit/test-post-saving.php b/tests/phpunit/test-post-saving.php index db82d27b..6401c48d 100644 --- a/tests/phpunit/test-post-saving.php +++ b/tests/phpunit/test-post-saving.php @@ -15,7 +15,7 @@ use function Authorship\get_authors; class TestPostSaving extends TestCase { - public function testPostAuthorshipDoesNotGetSavedOnPostTypeThatDoesNotSupportAuthor() : void { + public function testPostAuthorshipDoesNotGetSavedOnPostTypeThatDoesNotSupportAuthor(): void { $factory = self::factory()->post; register_post_type( 'testing', [ @@ -37,7 +37,7 @@ public function testPostAuthorshipDoesNotGetSavedOnPostTypeThatDoesNotSupportAut $this->assertCount( 0, $authors ); } - public function testPostAuthorshipIsRetainedWhenUpdatingPostWithNoAuthorshipParameter() : void { + public function testPostAuthorshipIsRetainedWhenUpdatingPostWithNoAuthorshipParameter(): void { $factory = self::factory()->post; // Attributed to Editor, owned by Admin. @@ -59,7 +59,7 @@ public function testPostAuthorshipIsRetainedWhenUpdatingPostWithNoAuthorshipPara $this->assertSame( [ self::$users['editor']->ID ], $author_ids ); } - public function testPostAuthorshipIsRetainedWhenUpdatingPostWithPostAuthorParameter() : void { + public function testPostAuthorshipIsRetainedWhenUpdatingPostWithPostAuthorParameter(): void { $factory = self::factory()->post; // Attributed to Editor, owned by Admin. @@ -81,7 +81,7 @@ public function testPostAuthorshipIsRetainedWhenUpdatingPostWithPostAuthorParame $this->assertSame( [ self::$users['editor']->ID ], $author_ids ); } - public function testPostAuthorshipIsSetToAuthorWhenCreatingPost() : void { + public function testPostAuthorshipIsSetToAuthorWhenCreatingPost(): void { /** @var int */ $post_id = wp_insert_post( [ 'post_title' => 'Testing', @@ -96,7 +96,7 @@ public function testPostAuthorshipIsSetToAuthorWhenCreatingPost() : void { $this->assertSame( [ self::$users['author']->ID ], $author_ids ); } - public function testPostAuthorshipIsSetToAuthorWhenUpdatingPostWithNoExistingAuthorship() : void { + public function testPostAuthorshipIsSetToAuthorWhenUpdatingPostWithNoExistingAuthorship(): void { $factory = self::factory()->post; // Owned by Author. @@ -115,7 +115,7 @@ public function testPostAuthorshipIsSetToAuthorWhenUpdatingPostWithNoExistingAut $this->assertSame( [ self::$users['author']->ID ], $author_ids ); } - public function testPostAuthorshipIsSetToEmptyWhenUpdatingPostWithNoExistingAuthorshipAndFiltered() : void { + public function testPostAuthorshipIsSetToEmptyWhenUpdatingPostWithNoExistingAuthorshipAndFiltered(): void { $factory = self::factory()->post; add_filter( 'authorship_default_author', '__return_empty_array' ); @@ -138,7 +138,7 @@ public function testPostAuthorshipIsSetToEmptyWhenUpdatingPostWithNoExistingAuth remove_filter( 'authorship_default_author', '__return_empty_array' ); } - public function testMultiplePostInsertionDoesNotCompoundActions() : void { + public function testMultiplePostInsertionDoesNotCompoundActions(): void { global $wp_filter; $before = count( $wp_filter['wp_insert_post']->callbacks ); diff --git a/tests/phpunit/test-rest-api-post-property.php b/tests/phpunit/test-rest-api-post-property.php index a26c3353..7b107497 100644 --- a/tests/phpunit/test-rest-api-post-property.php +++ b/tests/phpunit/test-rest-api-post-property.php @@ -18,7 +18,7 @@ use WP_REST_Request; class TestRESTAPIPostProperty extends RESTAPITestCase { - public function testAuthorshipCanBeSpecifiedWhenCreatingPost() : void { + public function testAuthorshipCanBeSpecifiedWhenCreatingPost(): void { wp_set_current_user( self::$users['admin']->ID ); $authors = [ @@ -38,7 +38,7 @@ public function testAuthorshipCanBeSpecifiedWhenCreatingPost() : void { $this->assertSame( $authors, $data[ REST_PARAM ] ); } - public function testAuthorshipOnlyAcceptsAnArray() : void { + public function testAuthorshipOnlyAcceptsAnArray(): void { wp_set_current_user( self::$users['admin']->ID ); $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); @@ -51,7 +51,7 @@ public function testAuthorshipOnlyAcceptsAnArray() : void { $this->assertSame( WP_Http::BAD_REQUEST, $response->get_status(), $message ); } - public function testAuthorshipCannotBeSpecifiedWhenCreatingAsAuthorRole() : void { + public function testAuthorshipCannotBeSpecifiedWhenCreatingAsAuthorRole(): void { wp_set_current_user( self::$users['author']->ID ); $authors = [ @@ -68,7 +68,7 @@ public function testAuthorshipCannotBeSpecifiedWhenCreatingAsAuthorRole() : void $this->assertSame( WP_Http::BAD_REQUEST, $response->get_status(), $message ); } - public function testAuthorshipCanBeSpecifiedWhenEditing() : void { + public function testAuthorshipCanBeSpecifiedWhenEditing(): void { wp_set_current_user( self::$users['admin']->ID ); $post = self::factory()->post->create_and_get( [ @@ -95,7 +95,7 @@ public function testAuthorshipCanBeSpecifiedWhenEditing() : void { $this->assertSame( $authors, $data[ REST_PARAM ] ); } - public function testAuthorshipIsRetainedWhenNotSpecifiedWhenEditing() : void { + public function testAuthorshipIsRetainedWhenNotSpecifiedWhenEditing(): void { wp_set_current_user( self::$users['admin']->ID ); $authors = [ @@ -122,7 +122,7 @@ public function testAuthorshipIsRetainedWhenNotSpecifiedWhenEditing() : void { $this->assertSame( $authors, $data[ REST_PARAM ] ); } - public function testAuthorshipIsRetainedWhenOnlyPostAuthorIsSpecifiedWhenEditing() : void { + public function testAuthorshipIsRetainedWhenOnlyPostAuthorIsSpecifiedWhenEditing(): void { wp_set_current_user( self::$users['admin']->ID ); $authors = [ @@ -149,7 +149,7 @@ public function testAuthorshipIsRetainedWhenOnlyPostAuthorIsSpecifiedWhenEditing $this->assertSame( $authors, $data[ REST_PARAM ] ); } - public function testAuthorshipPropertyExists() : void { + public function testAuthorshipPropertyExists(): void { $post = self::factory()->post->create_and_get( [ 'post_type' => 'post', 'post_status' => 'publish', @@ -168,7 +168,7 @@ public function testAuthorshipPropertyExists() : void { $this->assertSame( [ self::$users['editor']->ID ], $data[ REST_PARAM ] ); } - public function testAuthorshipLinksArePresent() : void { + public function testAuthorshipLinksArePresent(): void { wp_set_current_user( self::$users['admin']->ID ); $authors = [ @@ -194,7 +194,7 @@ public function testAuthorshipLinksArePresent() : void { $this->assertCount( 2, $links[ REST_LINK_ID ] ); } - public function testAuthorshipLinksAreEmbeddable() : void { + public function testAuthorshipLinksAreEmbeddable(): void { wp_set_current_user( self::$users['admin']->ID ); $authors = [ @@ -225,7 +225,7 @@ public function testAuthorshipLinksAreEmbeddable() : void { $this->assertSame( self::$users['editor']->display_name, $embedded[ REST_LINK_ID ][1]['name'] ); } - public function testRelLinksArePresent() : void { + public function testRelLinksArePresent(): void { wp_set_current_user( self::$users['admin']->ID ); $post = self::factory()->post->create_and_get(); diff --git a/tests/phpunit/test-rest-api-user-endpoint.php b/tests/phpunit/test-rest-api-user-endpoint.php index b3c4df6f..0120b1f3 100644 --- a/tests/phpunit/test-rest-api-user-endpoint.php +++ b/tests/phpunit/test-rest-api-user-endpoint.php @@ -27,7 +27,7 @@ class TestRESTAPIUserEndpoint extends RESTAPITestCase { */ protected static $route = '/' . Users_Controller::_NAMESPACE . '/' . Users_Controller::BASE; - public function testGuestAuthorCanBeCreatedWithJustAName() : void { + public function testGuestAuthorCanBeCreatedWithJustAName(): void { wp_set_current_user( self::$users['editor']->ID ); $request = new WP_REST_Request( 'POST', self::$route ); @@ -46,7 +46,7 @@ public function testGuestAuthorCanBeCreatedWithJustAName() : void { * * @param string $param */ - public function testFieldCannotBeSpecifiedWhenCreatingGuestAuthor( string $param ) : void { + public function testFieldCannotBeSpecifiedWhenCreatingGuestAuthor( string $param ): void { wp_set_current_user( self::$users['editor']->ID ); $request = new WP_REST_Request( 'POST', self::$route ); @@ -59,7 +59,7 @@ public function testFieldCannotBeSpecifiedWhenCreatingGuestAuthor( string $param $this->assertSame( WP_Http::FORBIDDEN, $response->get_status(), $message ); } - public function testUserOutputFieldsAreRestrictedWhenListingUsers() : void { + public function testUserOutputFieldsAreRestrictedWhenListingUsers(): void { wp_set_current_user( self::$users['editor']->ID ); $request = new WP_REST_Request( 'GET', self::$route ); @@ -82,7 +82,7 @@ public function testUserOutputFieldsAreRestrictedWhenListingUsers() : void { $this->assertEqualSets( $expected, array_keys( $data[0] ) ); } - public function testAllUsersAreListedWhenListingUsers() : void { + public function testAllUsersAreListedWhenListingUsers(): void { wp_set_current_user( self::$users['editor']->ID ); $request = new WP_REST_Request( 'GET', self::$route ); @@ -101,7 +101,7 @@ public function testAllUsersAreListedWhenListingUsers() : void { * * @param string $param */ - public function testUsersCannotBeFilteredByParameter( string $param ) : void { + public function testUsersCannotBeFilteredByParameter( string $param ): void { wp_set_current_user( self::$users['editor']->ID ); $request = new WP_REST_Request( 'GET', self::$route ); @@ -113,7 +113,7 @@ public function testUsersCannotBeFilteredByParameter( string $param ) : void { $this->assertSame( WP_Http::BAD_REQUEST, $response->get_status(), $message ); } - public function testContextCannotBeSetToEditWhenListingUsers() : void { + public function testContextCannotBeSetToEditWhenListingUsers(): void { wp_set_current_user( self::$users['editor']->ID ); $request = new WP_REST_Request( 'GET', self::$route ); @@ -125,7 +125,7 @@ public function testContextCannotBeSetToEditWhenListingUsers() : void { $this->assertSame( WP_Http::BAD_REQUEST, $response->get_status(), $message ); } - public function testPostTypeIsRequiredWhenListingUsers() : void { + public function testPostTypeIsRequiredWhenListingUsers(): void { wp_set_current_user( self::$users['editor']->ID ); $request = new WP_REST_Request( 'GET', self::$route ); @@ -142,7 +142,7 @@ public function testPostTypeIsRequiredWhenListingUsers() : void { $this->assertSame( [ 'post_type' ], $data['params'] ); } - public function testEndpointRequiresAuthentication() : void { + public function testEndpointRequiresAuthentication(): void { $request = new WP_REST_Request( 'GET', self::$route ); $request->set_param( 'search', 'testing' ); $request->set_param( 'post_type', 'post' ); @@ -158,7 +158,7 @@ public function testEndpointRequiresAuthentication() : void { * * @param string $orderby */ - public function testAllowedOrderByParameters( string $orderby ) : void { + public function testAllowedOrderByParameters( string $orderby ): void { wp_set_current_user( self::$users['editor']->ID ); $request = new WP_REST_Request( 'GET', self::$route ); @@ -176,7 +176,7 @@ public function testAllowedOrderByParameters( string $orderby ) : void { * * @param string $orderby */ - public function testDisallowedOrderByParameters( string $orderby ) : void { + public function testDisallowedOrderByParameters( string $orderby ): void { wp_set_current_user( self::$users['editor']->ID ); $request = new WP_REST_Request( 'GET', self::$route ); @@ -203,7 +203,7 @@ public function testDisallowedOrderByParameters( string $orderby ) : void { * @param string $role * @param bool $expected */ - public function testUserRolesThatCanListAuthors( string $role, bool $expected ) : void { + public function testUserRolesThatCanListAuthors( string $role, bool $expected ): void { wp_set_current_user( self::$users[ $role ]->ID ); $request = new WP_REST_Request( 'GET', self::$route ); @@ -225,7 +225,7 @@ public function testUserRolesThatCanListAuthors( string $role, bool $expected ) * @param string $role * @param bool $expected */ - public function testUserRolesThatCanCreateGuestAuthors( string $role, bool $expected ) : void { + public function testUserRolesThatCanCreateGuestAuthors( string $role, bool $expected ): void { wp_set_current_user( self::$users[ $role ]->ID ); $request = new WP_REST_Request( 'POST', self::$route ); @@ -247,7 +247,7 @@ public function testUserRolesThatCanCreateGuestAuthors( string $role, bool $expe * @param string $role * @param bool $expected */ - public function testGuestAuthorEmailIsAllowed( string $role, bool $expected ) : void { + public function testGuestAuthorEmailIsAllowed( string $role, bool $expected ): void { wp_set_current_user( self::$users[ $role ]->ID ); $request = new WP_REST_Request( 'POST', self::$route ); @@ -267,7 +267,7 @@ public function testGuestAuthorEmailIsAllowed( string $role, bool $expected ) : /** * @return mixed[] */ - public function dataAllowedOrderby() : array { + public function dataAllowedOrderby(): array { return [ [ 'id', @@ -281,7 +281,7 @@ public function dataAllowedOrderby() : array { /** * @return mixed[] */ - public function dataDisallowedOrderby() : array { + public function dataDisallowedOrderby(): array { return [ [ 'registered_date', @@ -304,7 +304,7 @@ public function dataDisallowedOrderby() : array { /** * @return mixed[] */ - public function dataDisallowedFilters() : array { + public function dataDisallowedFilters(): array { return [ [ 'roles', @@ -324,7 +324,7 @@ public function dataDisallowedFilters() : array { /** * @return mixed[] */ - public function dataDisallowedFields() : array { + public function dataDisallowedFields(): array { return [ [ 'password', @@ -338,7 +338,7 @@ public function dataDisallowedFields() : array { /** * @return mixed[] */ - public function dataRolesThatCanCreateGuestAuthors() : array { + public function dataRolesThatCanCreateGuestAuthors(): array { return [ [ 'admin', @@ -366,7 +366,7 @@ public function dataRolesThatCanCreateGuestAuthors() : array { /** * @return mixed[] */ - public function dataRolesThatCanAttributeAuthors() : array { + public function dataRolesThatCanAttributeAuthors(): array { return [ [ 'admin', @@ -394,7 +394,7 @@ public function dataRolesThatCanAttributeAuthors() : array { /** * @return mixed[] */ - public function dataRolesThatCanManageUsers() : array { + public function dataRolesThatCanManageUsers(): array { return [ [ 'admin', diff --git a/tests/phpunit/test-template.php b/tests/phpunit/test-template.php index 31825bef..f0f8211d 100644 --- a/tests/phpunit/test-template.php +++ b/tests/phpunit/test-template.php @@ -24,7 +24,7 @@ class TestTemplate extends TestCase { * @dataProvider dataAuthorsYes * @dataProvider dataAuthorsNo */ - public function testUserIsAuthor( bool $expected, callable $user, ?callable $post_author, callable ...$authorship ) : void { + public function testUserIsAuthor( bool $expected, callable $user, ?callable $post_author, callable ...$authorship ): void { $factory = self::factory()->post; if ( is_callable( $post_author ) ) { @@ -39,7 +39,7 @@ public function testUserIsAuthor( bool $expected, callable $user, ?callable $pos $post_authorship = array_map( 'call_user_func', $authorship ); /** @var int[] */ - $post_authorship = array_map( function( WP_User $user ) : int { + $post_authorship = array_map( function ( WP_User $user ): int { return $user->ID; }, $post_authorship ); @@ -60,7 +60,7 @@ public function testUserIsAuthor( bool $expected, callable $user, ?callable $pos /** * @dataProvider dataAuthorsYes */ - public function testAuthorIDs( bool $is_author, callable $user, ?callable $post_author, callable ...$authorship ) : void { + public function testAuthorIDs( bool $is_author, callable $user, ?callable $post_author, callable ...$authorship ): void { $factory = self::factory()->post; if ( is_callable( $post_author ) ) { @@ -72,7 +72,7 @@ public function testAuthorIDs( bool $is_author, callable $user, ?callable $post_ $post_authorship = array_map( 'call_user_func', $authorship ); /** @var int[] */ - $post_authorship = array_map( function( WP_User $user ) : int { + $post_authorship = array_map( function ( WP_User $user ): int { return $user->ID; }, $post_authorship ); @@ -93,7 +93,7 @@ public function testAuthorIDs( bool $is_author, callable $user, ?callable $post_ $this->assertSame( $expected, get_author_ids( $post ) ); } - public function testAuthorNames() : void { + public function testAuthorNames(): void { $factory = self::factory()->post; // Attributed to Editor, Author, and Admin. @@ -115,7 +115,7 @@ public function testAuthorNames() : void { $this->assertSame( $expected, get_author_names( $post ) ); } - public function testAuthorNamesInSentence() : void { + public function testAuthorNamesInSentence(): void { $factory = self::factory()->post; // Attributed to Editor, Author, and Admin. @@ -137,7 +137,7 @@ public function testAuthorNamesInSentence() : void { $this->assertSame( $expected, get_author_names_sentence( $post ) ); } - public function testAuthorNamesInList() : void { + public function testAuthorNamesInList(): void { $factory = self::factory()->post; // Attributed to Editor, Author, and Admin. @@ -173,56 +173,56 @@ public function testAuthorNamesInList() : void { /** * @return mixed[] */ - public function dataAuthorsYes() : array { + public function dataAuthorsYes(): array { return [ // Checking Admin, owned by Editor, attributed to Admin: [ true, - function() : WP_User { + function (): WP_User { return self::$users['admin']; }, - function() : WP_User { + function (): WP_User { return self::$users['editor']; }, - function() : WP_User { + function (): WP_User { return self::$users['admin']; }, ], // Checking Author, owned by nobody, attributed to Author: [ true, - function() : WP_User { + function (): WP_User { return self::$users['author']; }, null, - function() : WP_User { + function (): WP_User { return self::$users['author']; }, ], // Checking Editor, owned by nobody, attributed to Admin, Editor, and Author: [ true, - function() : WP_User { + function (): WP_User { return self::$users['editor']; }, null, - function() : WP_User { + function (): WP_User { return self::$users['admin']; }, - function() : WP_User { + function (): WP_User { return self::$users['editor']; }, - function() : WP_User { + function (): WP_User { return self::$users['author']; }, ], // Checking Editor, owned by Editor, attributed to nobody (inherits Editor): [ true, - function() : WP_User { + function (): WP_User { return self::$users['editor']; }, - function() : WP_User { + function (): WP_User { return self::$users['editor']; }, ], @@ -232,25 +232,25 @@ function() : WP_User { /** * @return mixed[] */ - public function dataAuthorsNo() : array { + public function dataAuthorsNo(): array { return [ // Checking Editor, owned by Editor, attributed to Admin: [ false, - function() : WP_User { + function (): WP_User { return self::$users['editor']; }, - function() : WP_User { + function (): WP_User { return self::$users['editor']; }, - function() : WP_User { + function (): WP_User { return self::$users['admin']; }, ], // Checking Author, owned by nobody, attributed to nobody: [ false, - function() : WP_User { + function (): WP_User { return self::$users['author']; }, null, @@ -258,10 +258,10 @@ function() : WP_User { // Checking Editor, owned by Admin, attributed to nobody: [ false, - function() : WP_User { + function (): WP_User { return self::$users['editor']; }, - function() : WP_User { + function (): WP_User { return self::$users['admin']; }, ], diff --git a/tests/phpunit/test-wp-query.php b/tests/phpunit/test-wp-query.php index 63b33d34..b8affabc 100644 --- a/tests/phpunit/test-wp-query.php +++ b/tests/phpunit/test-wp-query.php @@ -14,7 +14,7 @@ use WP_Query; class TestWPQuery extends TestCase { - public function testQueryForAuthorReturnsPostsAttributedToAuthor() : void { + public function testQueryForAuthorReturnsPostsAttributedToAuthor(): void { $factory = self::factory()->post; // Attributed to Editor, owned by Admin. @@ -97,7 +97,7 @@ public function testQueryForAuthorReturnsPostsAttributedToAuthor() : void { } } - public function testQueriedObjectIsRetainedAfterQueryingForAuthor() : void { + public function testQueriedObjectIsRetainedAfterQueryingForAuthor(): void { $factory = self::factory()->post; // Attributed to Editor, owned by Admin. @@ -141,7 +141,7 @@ public function testQueriedObjectIsRetainedAfterQueryingForAuthor() : void { } } - public function testQueryForInvalidAuthorReturnsNoResults() : void { + public function testQueryForInvalidAuthorReturnsNoResults(): void { $factory = self::factory()->post; // Attributed to Editor, owned by Admin. @@ -184,7 +184,7 @@ public function testQueryForInvalidAuthorReturnsNoResults() : void { } } - public function testQueryOverridesDoNotAffectPostTypesThatDoNotSupportAuthor() : void { + public function testQueryOverridesDoNotAffectPostTypesThatDoNotSupportAuthor(): void { $factory = self::factory()->post; register_post_type( 'testing', [ @@ -231,7 +231,7 @@ public function testQueryOverridesDoNotAffectPostTypesThatDoNotSupportAuthor() : } } - public function testQueryVarsRemainUnaffectedAfterQuery() : void { + public function testQueryVarsRemainUnaffectedAfterQuery(): void { $factory = self::factory()->post; // Attributed to Editor. @@ -282,7 +282,7 @@ public function testQueryVarsRemainUnaffectedAfterQuery() : void { $this->assertSame( [ self::$users['author']->ID ], $query->get( 'author__not_in' ) ); } - public function testSubsequentQueriesAreUnaffected() : void { + public function testSubsequentQueriesAreUnaffected(): void { $factory = self::factory()->post; // Attributed to Editor. From fde8b6fa5cdb6786ad629a757ecbf0777fdf2c31 Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Mon, 6 Apr 2026 13:55:40 -0400 Subject: [PATCH 4/6] Add .git-blame-ignore-revs for PHPCBF / ESLint bulk change commits --- .git-blame-ignore-revs | 1 + 1 file changed, 1 insertion(+) create mode 100644 .git-blame-ignore-revs diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 00000000..75828902 --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1 @@ +7de28976a6b6b099c18b39e130a3724e2da3760e From 7dfb4e52cd6b6f7ea0de388c897b819a46ef2622 Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Mon, 6 Apr 2026 13:57:31 -0400 Subject: [PATCH 5/6] PHPCS: Re-order use statements for consistency --- inc/admin.php | 4 ++-- tests/phpunit/test-post-saving.php | 4 ++-- tests/phpunit/test-rest-api-post-property.php | 6 +++--- tests/phpunit/test-rest-api-user-endpoint.php | 5 ++--- tests/phpunit/test-template.php | 4 ++-- tests/phpunit/test-wp-query.php | 4 ++-- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/inc/admin.php b/inc/admin.php index 7d1d0609..bb5c61e6 100644 --- a/inc/admin.php +++ b/inc/admin.php @@ -14,11 +14,11 @@ use WP_User; use stdClass; -use const Authorship\GUEST_ROLE; - use function Authorship\get_authors; use function Authorship\get_supported_post_types; +use const Authorship\GUEST_ROLE; + const COLUMN_NAME = 'authorship'; /** diff --git a/tests/phpunit/test-post-saving.php b/tests/phpunit/test-post-saving.php index 6401c48d..3481ad9a 100644 --- a/tests/phpunit/test-post-saving.php +++ b/tests/phpunit/test-post-saving.php @@ -9,11 +9,11 @@ namespace Authorship\Tests; +use function Authorship\get_authors; + use const Authorship\POSTS_PARAM; use const Authorship\TAXONOMY; -use function Authorship\get_authors; - class TestPostSaving extends TestCase { public function testPostAuthorshipDoesNotGetSavedOnPostTypeThatDoesNotSupportAuthor(): void { $factory = self::factory()->post; diff --git a/tests/phpunit/test-rest-api-post-property.php b/tests/phpunit/test-rest-api-post-property.php index 7b107497..db62810e 100644 --- a/tests/phpunit/test-rest-api-post-property.php +++ b/tests/phpunit/test-rest-api-post-property.php @@ -9,14 +9,14 @@ namespace Authorship\Tests; +use WP_Http; +use WP_REST_Request; + use const Authorship\POSTS_PARAM; use const Authorship\REST_LINK_ID; use const Authorship\REST_PARAM; use const Authorship\REST_REL_LINK_ID; -use WP_Http; -use WP_REST_Request; - class TestRESTAPIPostProperty extends RESTAPITestCase { public function testAuthorshipCanBeSpecifiedWhenCreatingPost(): void { wp_set_current_user( self::$users['admin']->ID ); diff --git a/tests/phpunit/test-rest-api-user-endpoint.php b/tests/phpunit/test-rest-api-user-endpoint.php index 0120b1f3..2a93bcbb 100644 --- a/tests/phpunit/test-rest-api-user-endpoint.php +++ b/tests/phpunit/test-rest-api-user-endpoint.php @@ -15,12 +15,11 @@ namespace Authorship\Tests; use Authorship\Users_Controller; - -use const Authorship\GUEST_ROLE; - use WP_Http; use WP_REST_Request; +use const Authorship\GUEST_ROLE; + class TestRESTAPIUserEndpoint extends RESTAPITestCase { /** * @var string diff --git a/tests/phpunit/test-template.php b/tests/phpunit/test-template.php index f0f8211d..e21784b5 100644 --- a/tests/phpunit/test-template.php +++ b/tests/phpunit/test-template.php @@ -9,7 +9,7 @@ namespace Authorship\Tests; -use const Authorship\POSTS_PARAM; +use WP_User; use function Authorship\get_author_ids; use function Authorship\get_author_names; @@ -17,7 +17,7 @@ use function Authorship\get_author_names_sentence; use function Authorship\user_is_author; -use WP_User; +use const Authorship\POSTS_PARAM; class TestTemplate extends TestCase { /** diff --git a/tests/phpunit/test-wp-query.php b/tests/phpunit/test-wp-query.php index b8affabc..d38905d4 100644 --- a/tests/phpunit/test-wp-query.php +++ b/tests/phpunit/test-wp-query.php @@ -9,10 +9,10 @@ namespace Authorship\Tests; -use const Authorship\POSTS_PARAM; - use WP_Query; +use const Authorship\POSTS_PARAM; + class TestWPQuery extends TestCase { public function testQueryForAuthorReturnsPostsAttributedToAuthor(): void { $factory = self::factory()->post; From 1e08f4bdfb95f73bbdc091d93eda8c25ded08f2e Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Mon, 6 Apr 2026 14:00:07 -0400 Subject: [PATCH 6/6] PHPCS: Disable escaping warning for thrown errors. Escaping belongs at the point of output (catch/render), not at throw. --- phpcs.xml.dist | 3 +++ 1 file changed, 3 insertions(+) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index fdf93771..5a951944 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -25,6 +25,9 @@ + + +