diff --git a/composer.json b/composer.json index 36e31d78..6d4a2282 100644 --- a/composer.json +++ b/composer.json @@ -4,9 +4,9 @@ "type": "wordpress-plugin", "require-dev": { "composer/installers": "~2.1", - "automattic/vipwpcs": "^2.0.0", + "automattic/vipwpcs": "^3.0", "brainmaestro/composer-git-hooks": "^2.6", - "wp-coding-standards/wpcs": "*", + "wp-coding-standards/wpcs": "^3.0", "dealerdirect/phpcodesniffer-composer-installer": "*", "phpcompatibility/phpcompatibility-wp": "*", "yoast/phpunit-polyfills": "^1.0", diff --git a/composer.lock b/composer.lock index e36cb1cc..439a1aae 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": "d88006e21b14057137f006f857f07c53", + "content-hash": "89a55370fcd148aa5679ddd767cc998f", "packages": [ { "name": "doctrine/deprecations", @@ -1570,24 +1570,25 @@ "packages-dev": [ { "name": "automattic/vipwpcs", - "version": "2.3.4", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/Automattic/VIP-Coding-Standards.git", - "reference": "b8610e3837f49c5f2fcc4b663b6c0a7c9b3509b6" + "reference": "1b8960ebff9ea3eb482258a906ece4d1ee1e25fd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Automattic/VIP-Coding-Standards/zipball/b8610e3837f49c5f2fcc4b663b6c0a7c9b3509b6", - "reference": "b8610e3837f49c5f2fcc4b663b6c0a7c9b3509b6", + "url": "https://api.github.com/repos/Automattic/VIP-Coding-Standards/zipball/1b8960ebff9ea3eb482258a906ece4d1ee1e25fd", + "reference": "1b8960ebff9ea3eb482258a906ece4d1ee1e25fd", "shasum": "" }, "require": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0", "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.1", - "wp-coding-standards/wpcs": "^2.3" + "squizlabs/php_codesniffer": "^3.7.2", + "wp-coding-standards/wpcs": "^3.0" }, "require-dev": { "php-parallel-lint/php-console-highlighter": "^1.0.0", @@ -1619,7 +1620,7 @@ "source": "https://github.com/Automattic/VIP-Coding-Standards", "wiki": "https://github.com/Automattic/VIP-Coding-Standards/wiki" }, - "time": "2023-08-24T15:11:13+00:00" + "time": "2023-09-05T11:01:05+00:00" }, { "name": "brainmaestro/composer-git-hooks", @@ -2386,6 +2387,172 @@ }, "time": "2022-10-24T09:00:36+00:00" }, + { + "name": "phpcsstandards/phpcsextra", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSExtra.git", + "reference": "11d387c6642b6e4acaf0bd9bf5203b8cca1ec489" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/11d387c6642b6e4acaf0bd9bf5203b8cca1ec489", + "reference": "11d387c6642b6e4acaf0bd9bf5203b8cca1ec489", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "phpcsstandards/phpcsutils": "^1.0.9", + "squizlabs/php_codesniffer": "^3.8.0" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "phpcsstandards/phpcsdevtools": "^1.2.1", + "phpunit/phpunit": "^4.5 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + }, + "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" + } + ], + "time": "2023-12-08T16:49:07+00:00" + }, + { + "name": "phpcsstandards/phpcsutils", + "version": "1.0.9", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSUtils.git", + "reference": "908247bc65010c7b7541a9551e002db12e9dae70" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/908247bc65010c7b7541a9551e002db12e9dae70", + "reference": "908247bc65010c7b7541a9551e002db12e9dae70", + "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.8.0 || 4.0.x-dev@dev" + }, + "require-dev": { + "ext-filter": "*", + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "yoast/phpunit-polyfills": "^1.1.0 || ^2.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", + "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" + } + ], + "time": "2023-12-08T14:50:00+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "9.2.29", @@ -3880,16 +4047,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.7.2", + "version": "3.8.0", "source": { "type": "git", - "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879" + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "5805f7a4e4958dbb5e944ef1e6edae0a303765e7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ed8e00df0a83aa96acf703f8c2979ff33341f879", - "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/5805f7a4e4958dbb5e944ef1e6edae0a303765e7", + "reference": "5805f7a4e4958dbb5e944ef1e6edae0a303765e7", "shasum": "" }, "require": { @@ -3899,7 +4066,7 @@ "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.0" }, "bin": [ "bin/phpcs", @@ -3918,22 +4085,45 @@ "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", "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" }, - "time": "2023-02-22T23:07:41+00:00" + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2023-12-08T12:32:31+00:00" }, { "name": "symfony/console", @@ -4582,30 +4772,38 @@ }, { "name": "wp-coding-standards/wpcs", - "version": "2.3.0", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", - "reference": "7da1894633f168fe244afc6de00d141f27517b62" + "reference": "b4caf9689f1a0e4a4c632679a44e638c1c67aff1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/7da1894633f168fe244afc6de00d141f27517b62", - "reference": "7da1894633f168fe244afc6de00d141f27517b62", + "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.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/", @@ -4622,6 +4820,7 @@ "keywords": [ "phpcs", "standards", + "static analysis", "wordpress" ], "support": { @@ -4629,7 +4828,13 @@ "source": "https://github.com/WordPress/WordPress-Coding-Standards", "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki" }, - "time": "2020-05-13T23:57:56+00:00" + "funding": [ + { + "url": "https://opencollective.com/thewpcc/contribute/wp-php-63406", + "type": "custom" + } + ], + "time": "2023-09-14T07:06:09+00:00" }, { "name": "yoast/phpunit-polyfills", @@ -4702,5 +4907,5 @@ "platform-overrides": { "php": "7.4" }, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.1.0" } diff --git a/includes/class-bidding.php b/includes/class-bidding.php index 486d3d97..31c24ff4 100644 --- a/includes/class-bidding.php +++ b/includes/class-bidding.php @@ -85,7 +85,7 @@ public static function get_price_granularities() { [ 'increment' => 0.5, 'max' => 20, - ], + ], ], ], 'dense' => [ @@ -190,11 +190,11 @@ public static function enqueue_scripts() { return; } wp_enqueue_script( - self::PREBID_SCRIPT_HANDLE, + self::PREBID_SCRIPT_HANDLE, plugins_url( '../dist/prebid.js', __FILE__ ), null, filemtime( dirname( NEWSPACK_ADS_PLUGIN_FILE ) . '/dist/prebid.js' ), - true + true ); add_filter( 'script_loader_tag', @@ -502,7 +502,7 @@ public static function is_enabled() { * * @return boolean Whether the bidder adapter is enabled. */ - public static function is_bidder_enabled( $bidder_id ) { + public static function is_bidder_enabled( $bidder_id ) { $enabled_bidders = Settings::get_setting( self::SETTINGS_SECTION_NAME, 'enabled_bidders', [] ); return in_array( $bidder_id, $enabled_bidders ); } @@ -626,7 +626,7 @@ function( $bidder_id, $bidder ) { ]; }, array_keys( $this->bidders ), - array_values( $this->bidders ) + array_values( $this->bidders ) ), ]; } @@ -707,7 +707,7 @@ public function register_settings( $settings_list ) { * * @return string[] Associative array containing a bidder key and name. */ -function get_bidders() { +function get_bidders() { // phpcs:ignore Universal.Files.SeparateFunctionsFromOO.Mixed return $GLOBALS['newspack_ads_bidding']->get_bidders(); } diff --git a/includes/class-custom-label.php b/includes/class-custom-label.php index f7ce3078..7581e4aa 100644 --- a/includes/class-custom-label.php +++ b/includes/class-custom-label.php @@ -104,6 +104,5 @@ function( $selector ) { placement = $placements[ $args['placement'] ]; } else { - return new \WP_Error( 'newspack_ads_placement_customize_control_no_placement', __( 'No placement specified.', 'newspack-ads' ) ); + return new \WP_Error( 'newspack_ads_placement_customize_control_no_placement', __( 'No placement specified.', 'newspack-ads' ) ); // phpcs:ignore Universal.CodeAnalysis.ConstructorDestructorReturn.ReturnValueFound } parent::__construct( $manager, $id, $args ); diff --git a/includes/providers/gam/api/class-api.php b/includes/providers/gam/api/class-api.php index 15f3fa6b..a3bc661e 100644 --- a/includes/providers/gam/api/class-api.php +++ b/includes/providers/gam/api/class-api.php @@ -85,13 +85,13 @@ class Api { public function __construct( $auth_method_or_session, $credentials = null, $network_code = null ) { if ( false === self::is_environment_compatible() ) { - throw new \Exception( __( 'The environment is not compatible with the GAM API.', 'newspack-ads' ) ); + throw new \Exception( esc_html__( 'The environment is not compatible with the GAM API.', 'newspack-ads' ) ); } if ( 'string' === gettype( $auth_method_or_session ) ) { $auth_method = $auth_method_or_session; if ( ! in_array( $auth_method, [ 'oauth2', 'service_account' ], true ) ) { - throw new \Exception( __( 'Invalid authentication method.', 'newspack-ads' ) ); + throw new \Exception( esc_html__( 'Invalid authentication method.', 'newspack-ads' ) ); } $this->auth_method = $auth_method; $this->credentials = $credentials; @@ -275,7 +275,7 @@ public function get_network( $session = null ) { $networks = $this->get_networks( $session ); $network_code = $this->network_code; if ( empty( $networks ) ) { - throw new \Exception( __( 'Missing GAM Ad network.', 'newspack-ads' ) ); + throw new \Exception( esc_html__( 'Missing GAM Ad network.', 'newspack-ads' ) ); } if ( $network_code ) { foreach ( $networks as $network ) { diff --git a/newspack-ads.php b/newspack-ads.php index 13f1e26b..0ad0bf00 100755 --- a/newspack-ads.php +++ b/newspack-ads.php @@ -25,5 +25,5 @@ // Include the main Newspack Ads class. if ( ! class_exists( 'Newspack_Ads\Core' ) ) { - include_once dirname( __FILE__ ) . '/includes/class-core.php'; + include_once __DIR__ . '/includes/class-core.php'; } diff --git a/phpcs.xml b/phpcs.xml index 1840a077..41cbafe2 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -8,6 +8,13 @@ + + + + + + + diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 97431ce6..382e4da0 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -42,7 +42,7 @@ class Newspack_Ads_Unit_Tests_Bootstrap { * Setup the unit testing environment. */ public function __construct() { - // phpcs:disable WordPress.PHP.DiscouragedPHPFunctions, WordPress.PHP.DevelopmentFunctions, WordPress.PHP.IniSet.display_errors_Blacklisted + // phpcs:disable WordPress.PHP.DiscouragedPHPFunctions, WordPress.PHP.DevelopmentFunctions, WordPress.PHP.IniSet.display_errors_Blacklisted, WordPress.PHP.IniSet.display_errors_Disallowed ini_set( 'display_errors', 'on' ); error_reporting( E_ALL ); // phpcs:enable WordPress.PHP.DiscouragedPHPFunctions, WordPress.PHP.DevelopmentFunctions @@ -54,7 +54,7 @@ public function __construct() { } // phpcs:enable WordPress.VIP.SuperGlobalInputUsage.AccessDetected - $this->tests_dir = dirname( __FILE__ ); + $this->tests_dir = __DIR__; $this->plugin_dir = dirname( $this->tests_dir ); $this->wp_tests_dir = getenv( 'WP_TESTS_DIR' ); if ( ! $this->wp_tests_dir ) { @@ -97,7 +97,7 @@ public function install_newspack_ads() { // include $this->plugin_dir . '/uninstall.php'; // Install the plugin here if needed. // Reload capabilities after install, see https://core.trac.wordpress.org/ticket/28374. - // phpcs:disable WordPress.WP.GlobalVariablesOverride.DeprecatedWhitelistCommentFound + // phpcs:disable WordPress.WP.GlobalVariablesOverride.DeprecatedWhitelistCommentFound, WordPress.WP.GlobalVariablesOverride.Prohibited $GLOBALS['wp_roles'] = null; // WPCS: override ok. wp_roles(); diff --git a/tests/test-providers.php b/tests/test-providers.php index 7956aa45..f62d383d 100644 --- a/tests/test-providers.php +++ b/tests/test-providers.php @@ -24,7 +24,7 @@ class ProvidersTest extends WP_UnitTestCase { * Set up test */ public function set_up() { - include_once dirname( __FILE__ ) . '/class-newspack-ads-test-provider.php'; + include_once __DIR__ . '/class-newspack-ads-test-provider.php'; // Register the test provider. self::$provider = new Newspack_Ads_Test_Provider(); Providers::register_provider( self::$provider );