From b2ca511aeccb0429c77c3fafa8375cf070cae6ad Mon Sep 17 00:00:00 2001 From: Paul Kevan Date: Tue, 21 May 2024 12:16:21 +0100 Subject: [PATCH] more phpcs --- phpcs.xml.dist | 103 +++++++++++++++++------- plugins/wporg-5ftf/includes/reports.php | 14 ++-- 2 files changed, 80 insertions(+), 37 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 5f98c99..94d3f74 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -1,33 +1,85 @@ - Apply customized version of WordPress Coding Standards to WordCamp.org projects. + Apply customized version of WordPress Coding Standards to WordCamp.org PHP scripts. - - */vendor/* - */node_modules/* + - /themes/pub/wporg + disable WordPress.VIP.PostsPerPage.posts_per_page_posts_per_page for bin folder only + should that be `WordPress.VIP.PostsPerPage.posts_per_page` ? - - /plugins/(?!wporg-5ftf) + Look through `General` and `Squiz` sniffs for anything you might want to add. + Is there one that detects `\Foo` instead of `use Foo`? + maximum nesting level? + function length? + unnecessary order-of-operations params, e.g., $foo = ( $bar || $qax ) ? 'bax' : 'quix'; + echoing html instead of breaking php or using an external view. e.g., echo '
foo
'; should be `?>
foo
tags without a blank line after/before them, except when doing single-line like + align ? and : in multiple ternary operator statements + don't un-align params in function calls - e.g., multiple add_meta_box( $a, $b, $c, $d, $e, $f, $g ) calls should have the params aligned. + file missing `defined WPINC or die` at start + don't add `@return void`, just leave return empty + no space before ++,etc operators: e.g., `$attempt_count ++;` + replace explicit references to central.wordcamp.org / ID `5` with `is_main_site()` or `get_main_site_id()` + anonymous functions used with add_(action|filter), and maybe other places can detect w/out false positives. don't be lazy. should only be used with cases like array_filter. + whitespace-only changes to lines that don't have logic changes, in a commit that does have logic changes. this indicates that a commit is mixing coding standards changes w/ logic changes, which adds diff noise to the logic change. they should be separate commits. + unnecessary parenthesis in ternary conditions: $result = ( $condition ) ? 'foo' : 'bar' + + Maybe add WordCamp\Remote_CSS\output_cached_css and wcorg_json_encode_attr_i18n to customEscapingFunctions or whichever param is most appropriate + Maybe do something similar for set_cache_headers and nonce verification + + Setup WordPress.WP.I18n text_domain property and test that it works, see https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#internationalization-setting-your-text-domain + + Don't add @package phpDoc? Clutters code without adding any real value. You know what "package" the file is part of because of the folder it's in; e.g., wp-content/plugins/wordcamp-payments + + Don't mush HTML elements together on the same line, unless it's really short. `

The title

` is ok, but `

` should have the h1 tags on separate lines. + + wp_enqueue_*() cachebusters should use filemtime() rather than a hardcoded int. + + Combine similar `use` statements on the same line. Like, all the core PHP objects, then all the WP objects on the 2nd line, then our custom objects on the 3rd line, etc. + + Prevent blank lines at start of function/class + --> + + */vendor/* + */node_modules/* + ./public_html/mu/* + . @@ -43,6 +95,9 @@ + + + @@ -64,7 +119,6 @@ - - - - + + + + + + + @@ -94,13 +152,6 @@ - - - */template-parts/content-5ftf_pledge.php$ - */archive-5ftf_pledge.php$ - */single-5ftf_pledge.php$ - - @@ -138,12 +189,4 @@ - - - - - - -
diff --git a/plugins/wporg-5ftf/includes/reports.php b/plugins/wporg-5ftf/includes/reports.php index dd0b70d..e3777b1 100644 --- a/plugins/wporg-5ftf/includes/reports.php +++ b/plugins/wporg-5ftf/includes/reports.php @@ -58,17 +58,17 @@ function render_company_report_page() { $status = sanitize_title( $_GET['status'] ); - if ( ! in_array( $status, array( 'draft','5ftf-deactivated','publish' ) ) ) { + if ( ! in_array( $status, array( 'draft', '5ftf-deactivated', 'publish' ) ) ) { $status = 'all'; } - $pledges = get_posts( [ + $pledges = get_posts( array( 'post_type' => '5ftf_pledge', 'post_status' => $status, 'posts_per_page' => 250, // set to 250 to avoid unexpected memory overuse. 'orderby' => 'post_title', 'order' => 'ASC', - ] ); + ) ); // Add visible warning on page if we hit the upper limit of the query. if ( 250 == count( $pledges ) ) { @@ -109,7 +109,7 @@ function render_company_report_page() { ID, '5ftf_org-domain', true ); $pledge_url = get_post_meta( $pledge->ID, '5ftf_org-url', true ); @@ -151,8 +151,8 @@ function render_company_report_page() { } /** - * CSV export runner, grabs data lazily from a transient. - * @param $data array. + * CSV export runner, grabs data lazily from a transient. + * @param $data array. */ function export_csv() { @@ -170,7 +170,7 @@ function export_csv() { $exporter = new Export_CSV( array( 'filename' => 'company-report-' . $status, - 'headers' => array( 'Company','Status','Hours','Contributors','Users','Teams','Company URL','Pledge URL','Email','Created','Last updated' ), + 'headers' => array( 'Company', 'Status', 'Hours', 'Contributors', 'Users', 'Teams', 'Company URL', 'Pledge URL', 'Email', 'Created', 'Last updated' ), 'data' => $data, ) );