Skip to content

Commit

Permalink
chore: update PHPCS
Browse files Browse the repository at this point in the history
  • Loading branch information
adekbadek committed Jan 11, 2024
1 parent 94b1a7f commit d3c4333
Show file tree
Hide file tree
Showing 10 changed files with 260 additions and 49 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
267 changes: 236 additions & 31 deletions composer.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions includes/class-bidding.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static function get_price_granularities() {
[
'increment' => 0.5,
'max' => 20,
],
],
],
],
'dense' => [
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -626,7 +626,7 @@ function( $bidder_id, $bidder ) {
];
},
array_keys( $this->bidders ),
array_values( $this->bidders )
array_values( $this->bidders )
),
];
}
Expand Down Expand Up @@ -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();
}

Expand Down
1 change: 0 additions & 1 deletion includes/class-custom-label.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,5 @@ function( $selector ) {
</style>
<?php
}

}
Custom_Label::init();
2 changes: 1 addition & 1 deletion includes/customizer/class-placement-customize-control.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct( $manager, $id, $args = [] ) {
$placements = Placements::get_placements();
$this->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 );
Expand Down
6 changes: 3 additions & 3 deletions includes/providers/gam/api/class-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion newspack-ads.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
7 changes: 7 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

<rule ref="WordPress">
<exclude name="Generic.Arrays.DisallowShortArraySyntax.Found" />
<exclude name="Universal.Arrays.DisallowShortArraySyntax.Found" />
<exclude name="Universal.Operators.DisallowStandalonePostIncrementDecrement.PostIncrementFound" />
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.SpaceAfterFunction" />
<exclude name="WordPress.PHP.YodaConditions.NotYoda" />
<exclude name="Generic.Formatting.MultipleStatementAlignment.NotSameWarning" />
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed" />
<exclude name="Universal.NamingConventions.NoReservedKeywordParameterNames" />
</rule>

<rule ref="PHPCompatibilityWP"/>
Expand Down
6 changes: 3 additions & 3 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ) {
Expand Down Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion tests/test-providers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit d3c4333

Please sign in to comment.