Tools: Add formatting command, run to fix minor phpcs issues

This commit is contained in:
Kelly Dwan 2024-08-27 13:40:37 -04:00
parent 28b102bc4c
commit bb25e0c78b
No known key found for this signature in database
GPG key ID: 8BA5575F3D11575D
13 changed files with 55 additions and 53 deletions

View file

@ -15,8 +15,9 @@
"build:theme": "npm run build --workspace=wporg-5ftf",
"start:theme": "npm run watch --workspace=wporg-5ftf",
"update:tools": "composer update && TEXTDOMAIN=wporg-5ftf composer exec update-configs",
"wp-env": "wp-env",
"lint:php": "composer lint ./themes/wporg-5ftf ./plugins/wporg-5ftf",
"wp-env": "wp-env"
"format:php": "composer format ./themes/wporg-5ftf ./plugins/wporg-5ftf",
},
"workspaces": [
"themes/wporg-5ftf",

View file

@ -181,4 +181,3 @@ function can_manage_pledge( $requested_pledge_id, $auth_token = '' ) {
__( 'Your link has expired.', 'wporg-5ftf' )
);
}

View file

@ -127,9 +127,9 @@ function send_contributor_confirmation_emails( $pledge_id, $contributor_id = nul
* @param WP_Post $contributor
*/
function send_contributor_removed_email( $pledge_id, $contributor ) {
$pledge = get_post( $pledge_id );
$subject = "Removed from {$pledge->post_title} Five for the Future pledge";
$user = get_user_by( 'login', $contributor->post_title );
$pledge = get_post( $pledge_id );
$subject = "Removed from {$pledge->post_title} Five for the Future pledge";
$user = get_user_by( 'login', $contributor->post_title );
$message = sprintf( '
Howdy %1$s,
@ -210,7 +210,7 @@ function send_pledge_deactivation_email( $pledge ) {
/**
* Ask an inactive contributor to update their pledge for accuracy.
*/
function send_contributor_inactive_email( array $contributor ) : bool {
function send_contributor_inactive_email( array $contributor ): bool {
/*
* Their first name is ideal, but their username is the best fallback because `nickname`, `display_name`,
* etc are too formal.
@ -218,7 +218,7 @@ function send_contributor_inactive_email( array $contributor ) : bool {
$name = empty( $contributor['first_name'] ) ? '@' . $contributor['user_nicename'] : $contributor['first_name'];
$subject = 'Please update your Five for the Future pledge';
$short_team_names = array_map( function( $team ) {
$short_team_names = array_map( function ( $team ) {
$team = str_replace( 'Team', '', $team );
return trim( $team );
@ -261,7 +261,7 @@ function send_contributor_inactive_email( array $contributor ) : bool {
/**
* Ask a company to update their pledge for accuracy.
*/
function send_pledge_update_email( WP_Post $pledge ) : bool {
function send_pledge_update_email( WP_Post $pledge ): bool {
$to = $pledge->{'5ftf_org-pledge-email'};
$subject = 'Please review your Five for the Future pledge';
$url = get_permalink( $pledge );
@ -281,7 +281,7 @@ function send_pledge_update_email( WP_Post $pledge ) : bool {
/**
* Ask a company to update their pledge for accuracy.
*/
function send_pledge_inactive_email( WP_Post $pledge ) : bool {
function send_pledge_inactive_email( WP_Post $pledge ): bool {
$to = $pledge->{'5ftf_org-pledge-email'};
$subject = 'Please review your Five for the Future pledge';
$url = get_permalink( $pledge );

View file

@ -2,7 +2,7 @@
namespace WordPressDotOrg\FiveForTheFuture\Miscellaneous;
add_action( 'after_setup_theme', function() {
add_action( 'after_setup_theme', function () {
// These alternate versions don't exist for this subsite, so the links would just lead to 404 errors.
remove_action( 'wp_head', 'WordPressdotorg\Theme\hreflang_link_attributes' );
} );

View file

@ -88,7 +88,7 @@ function get_pledge_log( $pledge_id ) {
return array();
}
usort( $log, function( $a, $b ) {
usort( $log, function ( $a, $b ) {
if ( $a['timestamp'] === $b['timestamp'] ) {
return 0;
}
@ -391,7 +391,7 @@ function capture_email_result( $to, $subject, $message, $headers, $result, $pled
/**
* Capture the results of an attempt to send an email.
*/
function capture_pledge_deactivation( int $pledge_id, bool $notify, string $reason, /* mixed */ $result ) : void {
function capture_pledge_deactivation( int $pledge_id, bool $notify, string $reason, /* mixed */ $result ): void {
add_log_entry(
$pledge_id,
'deactivated_pledge',

View file

@ -352,7 +352,7 @@ function is_active_pledge( $post_id ) {
function create_new_pledge( $name ) {
// Grab the ID of the post we are on before inserting a pledge.
$pledge_form_post_id = get_post()->ID;
$args = array(
$args = array(
'post_type' => CPT_ID,
'post_title' => $name,
'post_status' => 'draft',
@ -585,12 +585,12 @@ function send_update_reminders(): void {
'posts_per_page' => 15, // Limit # of emails to maintain IP reputation.
// New pledges haven't had time to become inaccurate yet.
'date_query' => array(
'date_query' => array(
'column' => 'post_date',
'before' => "$resend_interval seconds ago",
),
'meta_query' => array(
'meta_query' => array(
'relation' => 'AND',
array(

View file

@ -74,11 +74,11 @@ function render_company_report_page() {
}
$pledges = get_posts( array(
'post_type' => '5ftf_pledge',
'post_status' => $status,
'post_type' => '5ftf_pledge',
'post_status' => $status,
'posts_per_page' => $pledge_limit, // set to avoid unexpected memory overuse.
'orderby' => 'post_title',
'order' => 'ASC',
'orderby' => 'post_title',
'order' => 'ASC',
) );
// Add visible warning on page if we hit the upper limit of the query.
@ -122,18 +122,18 @@ function render_company_report_page() {
$export_data = array();
foreach ( $pledges as $pledge ) {
$company_url = get_post_meta( $pledge->ID, '5ftf_org-domain', true );
$email = get_post_meta( $pledge->ID, '5ftf_org-pledge-email', true );
$date_created = substr( $pledge->post_date, 0, 10 );
$date_modified = substr( $pledge->post_modified, 0, 10 );
$company_url = get_post_meta( $pledge->ID, '5ftf_org-domain', true );
$email = get_post_meta( $pledge->ID, '5ftf_org-pledge-email', true );
$date_created = substr( $pledge->post_date, 0, 10 );
$date_modified = substr( $pledge->post_modified, 0, 10 );
$team = XProfile\get_aggregate_contributor_data_for_pledge( $pledge->ID );
$hours = $team['hours'];
$contributors = $team['contributors'];
$team = XProfile\get_aggregate_contributor_data_for_pledge( $pledge->ID );
$hours = $team['hours'];
$contributors = $team['contributors'];
$all_contributors += $contributors;
$users = Contributor\get_pledge_contributors( $pledge->ID, 'publish' );
$wporg_profiles = wp_list_pluck( $users, 'post_title' );
$users = Contributor\get_pledge_contributors( $pledge->ID, 'publish' );
$wporg_profiles = wp_list_pluck( $users, 'post_title' );
$usernames = implode( ', ', $wporg_profiles );
$teams = implode( ', ', str_replace( ' Team', '', $team['teams'] ) );
@ -173,11 +173,11 @@ function render_contributor_report_page() {
}
$contributors = get_posts( array(
'post_type' => '5ftf_contributor',
'post_status' => $status,
'post_type' => '5ftf_contributor',
'post_status' => $status,
'posts_per_page' => $contributor_limit, // set to avoid unexpected memory overuse.
'orderby' => 'post_title',
'order' => 'ASC',
'orderby' => 'post_title',
'order' => 'ASC',
) );
// Add visible warning on page if we hit the upper limit of the query.
@ -221,7 +221,7 @@ function render_contributor_report_page() {
$pledge_company_title = get_the_title( $pledge_company ) ?? 'unattached';
$user_id = get_post_meta( $c->ID, 'wporg_user_id', true );
$xprofile = $all_contributor_data[ $user_id ] ?? [
'team_names' => [],
'team_names' => [],
'hours_per_week' => 0,
];
$xprofile_teams = $xprofile['team_names'] ?? [];

View file

@ -171,9 +171,9 @@ function get_snapshot_data() {
if ( Contributor\is_active( $user['last_logged_in'] ) ) {
if ( $is_company_sponsored ) {
$active_company_sponsored_contributors++;
++$active_company_sponsored_contributors;
} else {
$active_self_sponsored_contributors++;
++$active_self_sponsored_contributors;
}
} else {
$snapshot_data['inactive_contributor_ids'][] = $user['user_id'];
@ -185,7 +185,7 @@ function get_snapshot_data() {
foreach ( $user['team_names'] as $team ) {
if ( isset( $snapshot_data[ $team_contributor_key ][ $team ] ) ) {
$snapshot_data[ $team_contributor_key ][ $team ] ++;
++$snapshot_data[ $team_contributor_key ][ $team ];
} else {
$snapshot_data[ $team_contributor_key ][ $team ] = 1;
}

View file

@ -82,7 +82,7 @@ function get_all_xprofile_contributors_indexed(): array {
foreach ( $all_data as $contributor ) {
$newdata[ $contributor->user_id ] = [
'hours_per_week' => $contributor->hours_per_week,
'team_names' => $contributor->team_names,
'team_names' => $contributor->team_names,
];
}

View file

@ -21,9 +21,11 @@ require_once $_tests_dir . '/includes/functions.php';
* Manually load the plugin being tested.
*/
function _manually_load_plugin() {
define( 'WPORG_SUPPORT_FORUMS_BLOGID', 1 );
if ( ! defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) ) {
define( 'WPORG_SUPPORT_FORUMS_BLOGID', 1 );
}
require dirname( __FILE__, 2 ) . '/index.php';
require dirname( __DIR__, 1 ) . '/index.php';
require __DIR__ . '/helpers.php';
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );

View file

@ -9,7 +9,7 @@ use WP_UnitTest_Factory;
*
* Call in `set_up_before_class()`.
*/
function database_setup_before_class( WP_UnitTest_Factory $factory ) : array {
function database_setup_before_class( WP_UnitTest_Factory $factory ): array {
global $wpdb;
$fixtures = array();
@ -70,7 +70,7 @@ function database_setup_before_class( WP_UnitTest_Factory $factory ) : array {
) );
// Pages.
$for_organizations = $factory->post->create_and_get( array(
$for_organizations = $factory->post->create_and_get( array(
'post_type' => 'page',
'post_title' => 'For Organizations',
'post_status' => 'publish',
@ -103,7 +103,7 @@ function database_setup_before_class( WP_UnitTest_Factory $factory ) : array {
*
* Call in `set_up()`.
*/
function database_set_up( array $user_ids ) : void {
function database_set_up( array $user_ids ): void {
global $wpdb;
$wpdb->query( 'TRUNCATE TABLE `bpmain_bp_xprofile_data` ' );
@ -140,7 +140,7 @@ function database_set_up( array $user_ids ) : void {
*
* Call in `tear_down_after_class()`.
*/
function database_tear_down_after_class() : void {
function database_tear_down_after_class(): void {
global $wpdb;
$wpdb->query( 'DROP TABLE `bpmain_bp_xprofile_data` ' );

View file

@ -52,7 +52,7 @@ class Test_Auth extends WP_UnitTestCase {
/**
* Setup fixtures that are unique for each test.
*/
public function set_up() : void {
public function set_up(): void {
parent::set_up();
/*
@ -115,7 +115,7 @@ class Test_Auth extends WP_UnitTestCase {
'wrong-data-type' => array( 'this string is not an array' ),
'wrong-array-items' => array( 'this' => "doesn't have `value` and `expiration` items" ),
'invalid-value' => array(
'invalid-value' => array(
// Must have TOKEN_LENGTH characters, otherwise could be rejected for the wrong reason.
'value' => 'Has special characters !@#$%^&*)',
'expiration' => time() + MINUTE_IN_SECONDS,

View file

@ -55,7 +55,7 @@ class Test_Contributor extends WP_UnitTestCase {
* @covers WordPressDotOrg\FiveForTheFuture\XProfile\get_contributor_user_data
* @covers WordPressDotOrg\FiveForTheFuture\Pledge\deactivate
*/
public function test_data_reset_once_no_active_sponsors() : void {
public function test_data_reset_once_no_active_sponsors(): void {
// Setup scenario where Jane is sponsored by two companies.
$mailer = tests_retrieve_phpmailer_instance();
$jane = self::$users['jane'];
@ -122,7 +122,7 @@ class Test_Contributor extends WP_UnitTestCase {
* @covers WordPressDotOrg\FiveForTheFuture\XProfile\get_contributor_user_data
* @covers WordPressDotOrg\FiveForTheFuture\Pledge\deactivate
*/
public function test_data_not_reset_when_unconfirmed_sponsor() : void {
public function test_data_not_reset_when_unconfirmed_sponsor(): void {
// Setup scenario where Jane was invited to join a company but didn't respond.
$mailer = tests_retrieve_phpmailer_instance();
$jane = self::$users['jane'];
@ -163,7 +163,7 @@ class Test_Contributor extends WP_UnitTestCase {
* @covers WordPressDotOrg\FiveForTheFuture\Contributor\add_pledge_contributors
* @covers WordPressDotOrg\FiveForTheFuture\XProfile\get_contributor_user_data
*/
public function test_data_reset_when_single_contributor_removed_from_pledge() : void {
public function test_data_reset_when_single_contributor_removed_from_pledge(): void {
// Setup scenario where Jane and Ashish are sponsored by a company.
$mailer = tests_retrieve_phpmailer_instance();
$jane = self::$users['jane'];
@ -226,21 +226,21 @@ class Test_Contributor extends WP_UnitTestCase {
);
$contributors = array(
'active + due for email' => array(
'active + due for email' => array(
'user_id' => self::$users['jane']->ID,
'last_logged_in' => strtotime( '1 week ago' ),
'user_registered' => strtotime( '1 year ago' ),
'5ftf_last_inactivity_email' => 0,
),
'active + not due for email' => array(
'active + not due for email' => array(
'user_id' => self::$users['ashish']->ID,
'last_logged_in' => strtotime( '1 week ago' ),
'user_registered' => strtotime( '1 year ago' ),
'5ftf_last_inactivity_email' => strtotime( '1 month ago' ),
),
'inactive + due for email' => array(
'inactive + due for email' => array(
'user_id' => self::$users['andrea']->ID,
'last_logged_in' => strtotime( '4 months ago' ),
'user_registered' => strtotime( '1 year ago' ),
@ -254,14 +254,14 @@ class Test_Contributor extends WP_UnitTestCase {
'5ftf_last_inactivity_email' => strtotime( '2 months ago' ),
),
'new user' => array(
'new user' => array(
'user_id' => self::$users['jane']->ID,
'last_logged_in' => 0,
'user_registered' => strtotime( '1 week ago' ),
'5ftf_last_inactivity_email' => 0,
),
'inactive + blocked' => array(
'inactive + blocked' => array(
'user_id' => self::$users['kimi']->ID,
'last_logged_in' => strtotime( '4 months ago' ),
'user_registered' => strtotime( '1 year ago' ),