From aaaf705dbca32e336e8353e4b65789f1d83c2ef4 Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Mon, 25 Mar 2024 19:00:38 +0000 Subject: [PATCH 1/4] Satisfy missing parenthesis rule CS check introduced in WPCS 3.1.0 Error flagged is: Generic.CodeAnalysis.RequireExplicitBooleanOperatorPrecedence.MissingParentheses --- admin/class-enqueue-admin.php | 34 ++++++++++----------- includes/classes/class-enqueue-frontend.php | 12 ++++---- includes/rules/empty_button.php | 2 +- includes/rules/img_alt_empty.php | 10 +++--- includes/rules/img_alt_missing.php | 18 ++++++----- includes/rules/text_small.php | 6 ++-- 6 files changed, 42 insertions(+), 40 deletions(-) diff --git a/admin/class-enqueue-admin.php b/admin/class-enqueue-admin.php index d3b7234d..2a21cd25 100644 --- a/admin/class-enqueue-admin.php +++ b/admin/class-enqueue-admin.php @@ -36,8 +36,8 @@ public static function enqueue() { */ public static function enqueue_styles() { wp_enqueue_style( 'edac', plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/css/admin.css', array(), EDAC_VERSION, 'all' ); - } - + } + /** * Enqueue the admin and editorApp scripts. * @@ -57,13 +57,13 @@ public static function maybe_enqueue_admin_and_editor_app_scripts() { 'accessibility_checker_ignored', ); - if ( is_array( $post_types ) && count( $post_types ) && ( in_array( $current_post_type, $post_types, true ) || in_array( $page, $enabled_pages, true ) ) || ( 'site-editor.php' !== $pagenow ) ) { + if ( ( is_array( $post_types ) && count( $post_types ) && ( in_array( $current_post_type, $post_types, true ) || in_array( $page, $enabled_pages, true ) ) ) || ( 'site-editor.php' !== $pagenow ) ) { global $post; $post_id = is_object( $post ) ? $post->ID : null; wp_enqueue_script( 'edac', plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/admin.bundle.js', array( 'jquery' ), EDAC_VERSION, false ); - + wp_localize_script( 'edac', 'edac_script_vars', @@ -74,26 +74,26 @@ public static function maybe_enqueue_admin_and_editor_app_scripts() { 'restNonce' => wp_create_nonce( 'wp_rest' ), ) ); - + if ( 'post.php' === $pagenow ) { - + // Is this posttype setup to be checked? $post_types = get_option( 'edac_post_types' ); $current_post_type = get_post_type(); $active = ( is_array( $post_types ) && in_array( $current_post_type, $post_types, true ) ); - + $pro = is_plugin_active( 'accessibility-checker-pro/accessibility-checker-pro.php' ) && EDAC_KEY_VALID; - + if ( EDAC_DEBUG || strpos( EDAC_VERSION, '-beta' ) !== false ) { $debug = true; } else { $debug = false; } - + wp_enqueue_script( 'edac-editor-app', plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/editorApp.bundle.js', false, EDAC_VERSION, false ); - + wp_localize_script( 'edac-editor-app', 'edac_editor_app', @@ -107,13 +107,13 @@ public static function maybe_enqueue_admin_and_editor_app_scripts() { 'authOk' => false === (bool) get_option( 'edac_password_protected', false ), 'debug' => $debug, 'scanUrl' => get_preview_post_link( - $post_id, + $post_id, array( 'edac_pageScanner' => 1 ) ), ) ); - - } + + } } } @@ -125,13 +125,13 @@ public static function maybe_enqueue_admin_and_editor_app_scripts() { public static function maybe_enqueue_email_opt_in_script() { $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display only. - if ( 'accessibility_checker' === $page - && true !== (bool) get_user_meta( get_current_user_id(), 'edac_email_optin', true ) + if ( 'accessibility_checker' === $page + && true !== (bool) get_user_meta( get_current_user_id(), 'edac_email_optin', true ) ) { wp_enqueue_style( 'email-opt-in-form', plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/css/emailOptIn.css', false, EDAC_VERSION, 'all' ); wp_enqueue_script( 'email-opt-in-form', plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/emailOptIn.bundle.js', false, EDAC_VERSION, true ); - + wp_localize_script( 'email-opt-in-form', 'edac_email_opt_in_form', @@ -140,7 +140,7 @@ public static function maybe_enqueue_email_opt_in_script() { 'ajaxurl' => admin_url( 'admin-ajax.php' ), ) ); - + } } } diff --git a/includes/classes/class-enqueue-frontend.php b/includes/classes/class-enqueue-frontend.php index a78176a1..8b71bd67 100644 --- a/includes/classes/class-enqueue-frontend.php +++ b/includes/classes/class-enqueue-frontend.php @@ -26,20 +26,20 @@ public function __construct() { public static function enqueue() { self::maybe_enqueue_frontend_highlighter(); } - + /** * Enqueue the frontend highlighter. * * @return void */ public static function maybe_enqueue_frontend_highlighter() { - + // This loads on all pages, so bail as early as possible. Do checks that don't require DB calls first. // Don't load on admin pages in iframe that is running a pageScan. // phpcs:ignore WordPress.Security.NonceVerification.Recommended - if ( is_admin() || isset( $_GET['edac_pageScanner'] ) && '1' === $_GET['edac_pageScanner'] ) { + if ( is_admin() || ( isset( $_GET['edac_pageScanner'] ) && '1' === $_GET['edac_pageScanner'] ) ) { return; } @@ -55,17 +55,17 @@ public static function maybe_enqueue_frontend_highlighter() { if ( is_customize_preview() || ! ( $post_id && current_user_can( 'edit_post', $post_id ) ) ) { return; } - + // Don't load if this pagetype is not setup to be scanned. $post_types = get_option( 'edac_post_types' ); $current_post_type = get_post_type(); $active = ( is_array( $post_types ) && in_array( $current_post_type, $post_types, true ) ); - + if ( $active ) { - + wp_enqueue_style( 'edac-frontend-highlighter-app', plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/css/frontendHighlighterApp.css', false, EDAC_VERSION, 'all' ); wp_enqueue_script( 'edac-frontend-highlighter-app', plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/frontendHighlighterApp.bundle.js', false, EDAC_VERSION, false ); diff --git a/includes/rules/empty_button.php b/includes/rules/empty_button.php index 459ba3d6..c86ee677 100644 --- a/includes/rules/empty_button.php +++ b/includes/rules/empty_button.php @@ -41,7 +41,7 @@ function edac_rule_empty_button( $content, $post ) { // phpcs:ignore -- $post is '' !== $error_code && ( ! isset( $image[0] ) || trim( $image[0]->getAttribute( 'alt' ) ) === '' ) && ( ! isset( $input[0] ) || trim( $input[0]->getAttribute( 'value' ) ) === '' ) - && ( ! isset( $i[0] ) || ( trim( $i[0]->getAttribute( 'title' ) ) === '' ) && trim( $i[0]->getAttribute( 'aria-label' ) ) === '' ) + && ( ! isset( $i[0] ) || ( ( trim( $i[0]->getAttribute( 'title' ) ) === '' ) && ( trim( $i[0]->getAttribute( 'aria-label' ) ) === '' ) ) ) ) { $errors[] = $error_code; } diff --git a/includes/rules/img_alt_empty.php b/includes/rules/img_alt_empty.php index a277d227..bce48a03 100644 --- a/includes/rules/img_alt_empty.php +++ b/includes/rules/img_alt_empty.php @@ -23,11 +23,11 @@ function edac_rule_img_alt_empty( $content, $post ) { // phpcs:ignore -- $post i $elements = $dom->find( $tag ); foreach ( $elements as $element ) { if ( - isset( $element ) - && 'img' === $element->tag - && $element->hasAttribute( 'alt' ) - && $element->getAttribute( 'alt' ) === '' - && $element->getAttribute( 'role' ) !== 'presentation' + ( isset( $element ) + && 'img' === $element->tag + && $element->hasAttribute( 'alt' ) + && $element->getAttribute( 'alt' ) === '' + && $element->getAttribute( 'role' ) !== 'presentation' ) || ( 'input' === $element->tag && $element->hasAttribute( 'alt' ) && $element->getAttribute( 'type' ) === 'image' diff --git a/includes/rules/img_alt_missing.php b/includes/rules/img_alt_missing.php index 5100b981..eb5db32a 100644 --- a/includes/rules/img_alt_missing.php +++ b/includes/rules/img_alt_missing.php @@ -22,14 +22,16 @@ function edac_rule_img_alt_missing( $content, $post ) { // phpcs:ignore -- $post $elements = $dom->find( $tag ); foreach ( $elements as $element ) { - if ( isset( $element ) - && ( 'img' === $element->tag - && ! $element->hasAttribute( 'alt' ) - && $element->getAttribute( 'role' ) !== 'presentation' ) - && $element->getAttribute( 'aria-hidden' ) !== 'true' - || ( 'input' === $element->tag - && ! $element->hasAttribute( 'alt' ) - && $element->getAttribute( 'type' ) === 'image' ) + if ( ( isset( $element ) + && ( 'img' === $element->tag + && ! $element->hasAttribute( 'alt' ) + && $element->getAttribute( 'role' ) !== 'presentation' ) + && $element->getAttribute( 'aria-hidden' ) !== 'true' ) + || ( + 'input' === $element->tag + && ! $element->hasAttribute( 'alt' ) + && $element->getAttribute( 'type' ) === 'image' + ) ) { $image_code = $element->outertext; diff --git a/includes/rules/text_small.php b/includes/rules/text_small.php index 291ec039..da866ae2 100644 --- a/includes/rules/text_small.php +++ b/includes/rules/text_small.php @@ -43,8 +43,8 @@ function edac_rule_text_small( $content, $post ) { // phpcs:ignore -- $post is r preg_match_all( '!\d+!', $absolute_fontsize_errorcode, $matches ); if ( - stristr( $absolute_fontsize_errorcode, 'px' ) === 'px' && implode( ' ', $matches[0] ) <= 10 - || stristr( $absolute_fontsize_errorcode, 'pt' ) === 'pt' && implode( ' ', $matches[0] ) <= 13 + ( stristr( $absolute_fontsize_errorcode, 'px' ) === 'px' && implode( ' ', $matches[0] ) <= 10 ) + || ( ( stristr( $absolute_fontsize_errorcode, 'pt' ) === 'pt' ) && ( implode( ' ', $matches[0] ) <= 13 ) ) ) { $errors[] = $element; } @@ -86,7 +86,7 @@ function ac_css_small_text_check( $content ) { $value = str_replace( '.', '', preg_replace( '/\d/', '', $rules['font-size'] ) ); - if ( 'px' === $value && $rules['font-size'] <= 10 || 'pt' === $value && $rules['font-size'] <= 13 ) { + if ( ( 'px' === $value && $rules['font-size'] <= 10 ) || ( 'pt' === $value && $rules['font-size'] <= 13 ) ) { $error_code = $element . '{ '; foreach ( $rules as $key => $value ) { From e5539c6c73d49bf75f73491da1b0b2a88014a3dc Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Mon, 25 Mar 2024 21:00:13 +0000 Subject: [PATCH 2/4] Improve readability of some of the conditions that had new clarifying parenthesis added --- admin/class-enqueue-admin.php | 12 +++++++++++- includes/classes/class-enqueue-frontend.php | 9 +++++++-- includes/rules/empty_button.php | 8 +++++++- includes/rules/img_alt_empty.php | 11 +++++++---- includes/rules/img_alt_missing.php | 20 ++++++++++++-------- includes/rules/text_small.php | 14 +++++++++++--- 6 files changed, 55 insertions(+), 19 deletions(-) diff --git a/admin/class-enqueue-admin.php b/admin/class-enqueue-admin.php index 2a21cd25..f4c590bc 100644 --- a/admin/class-enqueue-admin.php +++ b/admin/class-enqueue-admin.php @@ -57,7 +57,17 @@ public static function maybe_enqueue_admin_and_editor_app_scripts() { 'accessibility_checker_ignored', ); - if ( ( is_array( $post_types ) && count( $post_types ) && ( in_array( $current_post_type, $post_types, true ) || in_array( $page, $enabled_pages, true ) ) ) || ( 'site-editor.php' !== $pagenow ) ) { + if ( + ( + is_array( $post_types ) && + count( $post_types ) && + ( + in_array( $current_post_type, $post_types, true ) || + in_array( $page, $enabled_pages, true ) + ) + ) || + 'site-editor.php' !== $pagenow + ) { global $post; $post_id = is_object( $post ) ? $post->ID : null; diff --git a/includes/classes/class-enqueue-frontend.php b/includes/classes/class-enqueue-frontend.php index 8b71bd67..430e6847 100644 --- a/includes/classes/class-enqueue-frontend.php +++ b/includes/classes/class-enqueue-frontend.php @@ -38,8 +38,13 @@ public static function maybe_enqueue_frontend_highlighter() { // Don't load on admin pages in iframe that is running a pageScan. - // phpcs:ignore WordPress.Security.NonceVerification.Recommended - if ( is_admin() || ( isset( $_GET['edac_pageScanner'] ) && '1' === $_GET['edac_pageScanner'] ) ) { + if ( + is_admin() || + ( + isset( $_GET['edac_pageScanner'] ) && // phpcs:ignore WordPress.Security.NonceVerification.Recommended + '1' === $_GET['edac_pageScanner'] // phpcs:ignore WordPress.Security.NonceVerification.Recommended + ) + ) { return; } diff --git a/includes/rules/empty_button.php b/includes/rules/empty_button.php index c86ee677..8781775c 100644 --- a/includes/rules/empty_button.php +++ b/includes/rules/empty_button.php @@ -41,7 +41,13 @@ function edac_rule_empty_button( $content, $post ) { // phpcs:ignore -- $post is '' !== $error_code && ( ! isset( $image[0] ) || trim( $image[0]->getAttribute( 'alt' ) ) === '' ) && ( ! isset( $input[0] ) || trim( $input[0]->getAttribute( 'value' ) ) === '' ) - && ( ! isset( $i[0] ) || ( ( trim( $i[0]->getAttribute( 'title' ) ) === '' ) && ( trim( $i[0]->getAttribute( 'aria-label' ) ) === '' ) ) ) + && ( + ! isset( $i[0] ) || + ( + ( trim( $i[0]->getAttribute( 'title' ) ) === '' ) && + ( trim( $i[0]->getAttribute( 'aria-label' ) ) === '' ) + ) + ) ) { $errors[] = $error_code; } diff --git a/includes/rules/img_alt_empty.php b/includes/rules/img_alt_empty.php index bce48a03..a3ee5b60 100644 --- a/includes/rules/img_alt_empty.php +++ b/includes/rules/img_alt_empty.php @@ -23,15 +23,18 @@ function edac_rule_img_alt_empty( $content, $post ) { // phpcs:ignore -- $post i $elements = $dom->find( $tag ); foreach ( $elements as $element ) { if ( - ( isset( $element ) + ( + isset( $element ) && 'img' === $element->tag && $element->hasAttribute( 'alt' ) && $element->getAttribute( 'alt' ) === '' - && $element->getAttribute( 'role' ) !== 'presentation' ) - || ( 'input' === $element->tag + && $element->getAttribute( 'role' ) !== 'presentation' + ) || ( + 'input' === $element->tag && $element->hasAttribute( 'alt' ) && $element->getAttribute( 'type' ) === 'image' - && $element->getAttribute( 'alt' ) === '' ) + && $element->getAttribute( 'alt' ) === '' + ) ) { $image_code = $element->outertext; diff --git a/includes/rules/img_alt_missing.php b/includes/rules/img_alt_missing.php index eb5db32a..2d57b801 100644 --- a/includes/rules/img_alt_missing.php +++ b/includes/rules/img_alt_missing.php @@ -22,15 +22,19 @@ function edac_rule_img_alt_missing( $content, $post ) { // phpcs:ignore -- $post $elements = $dom->find( $tag ); foreach ( $elements as $element ) { - if ( ( isset( $element ) - && ( 'img' === $element->tag + if ( + ( + isset( $element ) && + ( + 'img' === $element->tag && ! $element->hasAttribute( 'alt' ) - && $element->getAttribute( 'role' ) !== 'presentation' ) - && $element->getAttribute( 'aria-hidden' ) !== 'true' ) - || ( - 'input' === $element->tag - && ! $element->hasAttribute( 'alt' ) - && $element->getAttribute( 'type' ) === 'image' + && $element->getAttribute( 'role' ) !== 'presentation' + ) + && $element->getAttribute( 'aria-hidden' ) !== 'true' + ) || ( + 'input' === $element->tag + && ! $element->hasAttribute( 'alt' ) + && $element->getAttribute( 'type' ) === 'image' ) ) { diff --git a/includes/rules/text_small.php b/includes/rules/text_small.php index da866ae2..abce7e85 100644 --- a/includes/rules/text_small.php +++ b/includes/rules/text_small.php @@ -43,8 +43,13 @@ function edac_rule_text_small( $content, $post ) { // phpcs:ignore -- $post is r preg_match_all( '!\d+!', $absolute_fontsize_errorcode, $matches ); if ( - ( stristr( $absolute_fontsize_errorcode, 'px' ) === 'px' && implode( ' ', $matches[0] ) <= 10 ) - || ( ( stristr( $absolute_fontsize_errorcode, 'pt' ) === 'pt' ) && ( implode( ' ', $matches[0] ) <= 13 ) ) + ( + stristr( $absolute_fontsize_errorcode, 'px' ) === 'px' && + implode( ' ', $matches[0] ) <= 10 + ) || ( + ( stristr( $absolute_fontsize_errorcode, 'pt' ) === 'pt' ) && + ( implode( ' ', $matches[0] ) <= 13 ) + ) ) { $errors[] = $element; } @@ -86,7 +91,10 @@ function ac_css_small_text_check( $content ) { $value = str_replace( '.', '', preg_replace( '/\d/', '', $rules['font-size'] ) ); - if ( ( 'px' === $value && $rules['font-size'] <= 10 ) || ( 'pt' === $value && $rules['font-size'] <= 13 ) ) { + if ( + ( 'px' === $value && $rules['font-size'] <= 10 ) || + ( 'pt' === $value && $rules['font-size'] <= 13 ) + ) { $error_code = $element . '{ '; foreach ( $rules as $key => $value ) { From 30b6f7c662fe6b1970123c2b93632f1cb790ff9b Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Mon, 25 Mar 2024 21:06:27 +0000 Subject: [PATCH 3/4] Bump wpcs to 3.1 or above --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index f2dac2a8..53777fa7 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "yoast/phpunit-polyfills": "^1.1.0", "yoast/wp-test-utils": "^1.2", "phpcompatibility/phpcompatibility-wp": "^2.1", - "wp-coding-standards/wpcs": "^3.0", + "wp-coding-standards/wpcs": "^3.1", "equalizedigital/accessibility-checker-wp-env": "*", "doctrine/instantiator": "^1.3.1", "wp-phpunit/wp-phpunit": "*" @@ -68,7 +68,7 @@ "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf" ], "test": [ - "@php ./vendor/phpunit/phpunit/phpunit" + "@php ./vendor/phpunit/phpunit/phpunit --coverage-html ./tests/_output/report" ] } -} \ No newline at end of file +} From 2a5b3b4307b9f3610a74e005bebb543efa3b2b3d Mon Sep 17 00:00:00 2001 From: pattonwebz Date: Mon, 25 Mar 2024 21:10:11 +0000 Subject: [PATCH 4/4] Revert "Bump wpcs to 3.1 or above" This reverts commit 30b6f7c662fe6b1970123c2b93632f1cb790ff9b. --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 53777fa7..f2dac2a8 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "yoast/phpunit-polyfills": "^1.1.0", "yoast/wp-test-utils": "^1.2", "phpcompatibility/phpcompatibility-wp": "^2.1", - "wp-coding-standards/wpcs": "^3.1", + "wp-coding-standards/wpcs": "^3.0", "equalizedigital/accessibility-checker-wp-env": "*", "doctrine/instantiator": "^1.3.1", "wp-phpunit/wp-phpunit": "*" @@ -68,7 +68,7 @@ "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf" ], "test": [ - "@php ./vendor/phpunit/phpunit/phpunit --coverage-html ./tests/_output/report" + "@php ./vendor/phpunit/phpunit/phpunit" ] } -} +} \ No newline at end of file