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", "build:theme": "npm run build --workspace=wporg-5ftf",
"start:theme": "npm run watch --workspace=wporg-5ftf", "start:theme": "npm run watch --workspace=wporg-5ftf",
"update:tools": "composer update && TEXTDOMAIN=wporg-5ftf composer exec update-configs", "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", "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": [ "workspaces": [
"themes/wporg-5ftf", "themes/wporg-5ftf",

View file

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

View file

@ -210,7 +210,7 @@ function send_pledge_deactivation_email( $pledge ) {
/** /**
* Ask an inactive contributor to update their pledge for accuracy. * 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`, * Their first name is ideal, but their username is the best fallback because `nickname`, `display_name`,
* etc are too formal. * 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']; $name = empty( $contributor['first_name'] ) ? '@' . $contributor['user_nicename'] : $contributor['first_name'];
$subject = 'Please update your Five for the Future pledge'; $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 ); $team = str_replace( 'Team', '', $team );
return trim( $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. * 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'}; $to = $pledge->{'5ftf_org-pledge-email'};
$subject = 'Please review your Five for the Future pledge'; $subject = 'Please review your Five for the Future pledge';
$url = get_permalink( $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. * 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'}; $to = $pledge->{'5ftf_org-pledge-email'};
$subject = 'Please review your Five for the Future pledge'; $subject = 'Please review your Five for the Future pledge';
$url = get_permalink( $pledge ); $url = get_permalink( $pledge );

View file

@ -2,7 +2,7 @@
namespace WordPressDotOrg\FiveForTheFuture\Miscellaneous; 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. // 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' ); remove_action( 'wp_head', 'WordPressdotorg\Theme\hreflang_link_attributes' );
} ); } );

View file

@ -88,7 +88,7 @@ function get_pledge_log( $pledge_id ) {
return array(); return array();
} }
usort( $log, function( $a, $b ) { usort( $log, function ( $a, $b ) {
if ( $a['timestamp'] === $b['timestamp'] ) { if ( $a['timestamp'] === $b['timestamp'] ) {
return 0; 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. * 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( add_log_entry(
$pledge_id, $pledge_id,
'deactivated_pledge', 'deactivated_pledge',

View file

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

View file

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

View file

@ -9,7 +9,7 @@ use WP_UnitTest_Factory;
* *
* Call in `set_up_before_class()`. * 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; global $wpdb;
$fixtures = array(); $fixtures = array();
@ -103,7 +103,7 @@ function database_setup_before_class( WP_UnitTest_Factory $factory ) : array {
* *
* Call in `set_up()`. * Call in `set_up()`.
*/ */
function database_set_up( array $user_ids ) : void { function database_set_up( array $user_ids ): void {
global $wpdb; global $wpdb;
$wpdb->query( 'TRUNCATE TABLE `bpmain_bp_xprofile_data` ' ); $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()`. * Call in `tear_down_after_class()`.
*/ */
function database_tear_down_after_class() : void { function database_tear_down_after_class(): void {
global $wpdb; global $wpdb;
$wpdb->query( 'DROP TABLE `bpmain_bp_xprofile_data` ' ); $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. * Setup fixtures that are unique for each test.
*/ */
public function set_up() : void { public function set_up(): void {
parent::set_up(); parent::set_up();
/* /*

View file

@ -55,7 +55,7 @@ class Test_Contributor extends WP_UnitTestCase {
* @covers WordPressDotOrg\FiveForTheFuture\XProfile\get_contributor_user_data * @covers WordPressDotOrg\FiveForTheFuture\XProfile\get_contributor_user_data
* @covers WordPressDotOrg\FiveForTheFuture\Pledge\deactivate * @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. // Setup scenario where Jane is sponsored by two companies.
$mailer = tests_retrieve_phpmailer_instance(); $mailer = tests_retrieve_phpmailer_instance();
$jane = self::$users['jane']; $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\XProfile\get_contributor_user_data
* @covers WordPressDotOrg\FiveForTheFuture\Pledge\deactivate * @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. // Setup scenario where Jane was invited to join a company but didn't respond.
$mailer = tests_retrieve_phpmailer_instance(); $mailer = tests_retrieve_phpmailer_instance();
$jane = self::$users['jane']; $jane = self::$users['jane'];
@ -163,7 +163,7 @@ class Test_Contributor extends WP_UnitTestCase {
* @covers WordPressDotOrg\FiveForTheFuture\Contributor\add_pledge_contributors * @covers WordPressDotOrg\FiveForTheFuture\Contributor\add_pledge_contributors
* @covers WordPressDotOrg\FiveForTheFuture\XProfile\get_contributor_user_data * @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. // Setup scenario where Jane and Ashish are sponsored by a company.
$mailer = tests_retrieve_phpmailer_instance(); $mailer = tests_retrieve_phpmailer_instance();
$jane = self::$users['jane']; $jane = self::$users['jane'];