Apply coding standards

This commit is contained in:
Ian Dunn 2023-11-06 09:53:47 -08:00
parent b86470575f
commit ed490dfc26
3 changed files with 38 additions and 38 deletions

View file

@ -197,7 +197,7 @@ function add_pledge_contributors( $pledge_id, $contributors ) {
* Some contributors are sponsored by multiple companies. They'll have a `5ftf_contributor` post for each company, * Some contributors are sponsored by multiple companies. They'll have a `5ftf_contributor` post for each company,
* but only the post associated with the given pledge should be removed. * but only the post associated with the given pledge should be removed.
*/ */
function remove_pledge_contributors( int $pledge_id ) : void { function remove_pledge_contributors( int $pledge_id ): void {
$contributors = get_pledge_contributors( $pledge_id, 'all' ); $contributors = get_pledge_contributors( $pledge_id, 'all' );
foreach ( $contributors as $status_group ) { foreach ( $contributors as $status_group ) {
@ -291,7 +291,7 @@ function get_pledge_contributors( $pledge_id, $status = 'publish', $contributor_
if ( empty( $posts ) ) { if ( empty( $posts ) ) {
$posts = $initial; $posts = $initial;
} else { } else {
$posts = array_reduce( $posts, function( $carry, WP_Post $item ) { $posts = array_reduce( $posts, function ( $carry, WP_Post $item ) {
$carry[ $item->post_status ][] = $item; $carry[ $item->post_status ][] = $item;
return $carry; return $carry;
@ -318,7 +318,7 @@ function get_pledge_contributors_data( $pledge_id ) {
foreach ( $contributors as $contributor_status => $group ) { foreach ( $contributors as $contributor_status => $group ) {
$contrib_data[ $contributor_status ] = array_map( $contrib_data[ $contributor_status ] = array_map(
function( $contributor_post ) use ( $contributor_status, $pledge_id ) { function ( $contributor_post ) use ( $contributor_status, $pledge_id ) {
$name = $contributor_post->post_title; $name = $contributor_post->post_title;
$contributor = get_user_by( 'login', $name ); $contributor = get_user_by( 'login', $name );
@ -352,7 +352,7 @@ function get_pledge_contributors_data( $pledge_id ) {
* @return WP_User[] * @return WP_User[]
*/ */
function get_contributor_user_objects( array $contributor_posts ) { function get_contributor_user_objects( array $contributor_posts ) {
return array_map( function( WP_Post $post ) { return array_map( function ( WP_Post $post ) {
return get_user_by( 'login', $post->post_title ); return get_user_by( 'login', $post->post_title );
}, $contributor_posts ); }, $contributor_posts );
} }
@ -601,7 +601,7 @@ function parse_contributors( $contributors, $pledge_id = null ) {
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
function notify_inactive_contributors() : void { function notify_inactive_contributors(): void {
$contributors = get_inactive_contributor_batch(); $contributors = get_inactive_contributor_batch();
$contributors = prune_unnotifiable_xprofiles( $contributors ); $contributors = prune_unnotifiable_xprofiles( $contributors );
$contributors = add_user_data_to_xprofile( $contributors ); $contributors = add_user_data_to_xprofile( $contributors );
@ -624,7 +624,7 @@ function notify_inactive_contributors() : void {
/** /**
* Get the next group of inactive contributors. * Get the next group of inactive contributors.
*/ */
function get_inactive_contributor_batch() : array { function get_inactive_contributor_batch(): array {
global $wpdb; global $wpdb;
$batch_size = 500; // This can be large because most users will be pruned later on. $batch_size = 500; // This can be large because most users will be pruned later on.
@ -677,7 +677,7 @@ function get_inactive_contributor_batch() : array {
/** /**
* Prune xprofile rows for users who shouldn't be notified of their inactivity. * Prune xprofile rows for users who shouldn't be notified of their inactivity.
*/ */
function prune_unnotifiable_xprofiles( array $xprofiles ) : array { function prune_unnotifiable_xprofiles( array $xprofiles ): array {
$notifiable_teams = array( 'Polyglots Team', 'Training Team' ); $notifiable_teams = array( 'Polyglots Team', 'Training Team' );
foreach ( $xprofiles as $index => $xprofile ) { foreach ( $xprofiles as $index => $xprofile ) {
@ -710,7 +710,7 @@ function prune_unnotifiable_xprofiles( array $xprofiles ) : array {
/** /**
* Merge user data with xprofile data. * Merge user data with xprofile data.
*/ */
function add_user_data_to_xprofile( array $xprofiles ) : array { function add_user_data_to_xprofile( array $xprofiles ): array {
global $wpdb; global $wpdb;
if ( empty( $xprofiles ) ) { if ( empty( $xprofiles ) ) {
@ -777,7 +777,7 @@ function add_user_data_to_xprofile( array $xprofiles ) : array {
/** /**
* Prune users who shouldn't be notified of their inactivity. * Prune users who shouldn't be notified of their inactivity.
*/ */
function prune_unnotifiable_users( array $contributors ) : array { function prune_unnotifiable_users( array $contributors ): array {
$inactivity_threshold = strtotime( INACTIVITY_THRESHOLD_MONTHS . ' months ago' ); $inactivity_threshold = strtotime( INACTIVITY_THRESHOLD_MONTHS . ' months ago' );
foreach ( $contributors as $index => $contributor ) { foreach ( $contributors as $index => $contributor ) {
@ -817,7 +817,7 @@ function prune_unnotifiable_users( array $contributors ) : array {
* *
* @link https://github.com/WordPress/five-for-the-future/issues/210 * @link https://github.com/WordPress/five-for-the-future/issues/210
*/ */
function is_active( int $last_login ) : bool { function is_active( int $last_login ): bool {
$inactivity_threshold = strtotime( INACTIVITY_THRESHOLD_MONTHS . ' months ago' ); $inactivity_threshold = strtotime( INACTIVITY_THRESHOLD_MONTHS . ' months ago' );
return $last_login > $inactivity_threshold; return $last_login > $inactivity_threshold;
@ -826,7 +826,7 @@ function is_active( int $last_login ) : bool {
/** /**
* Notify an inactive contributor. * Notify an inactive contributor.
*/ */
function notify_inactive_contributor( array $contributor ) : void { function notify_inactive_contributor( array $contributor ): void {
if ( ! Email\send_contributor_inactive_email( $contributor ) ) { if ( ! Email\send_contributor_inactive_email( $contributor ) ) {
return; return;
} }

View file

@ -22,7 +22,7 @@ defined( 'WPINC' ) || die();
* The "Sponsored" field is not retrieved because it's usually not needed, and including it would significantly * The "Sponsored" field is not retrieved because it's usually not needed, and including it would significantly
* hurt performance. * hurt performance.
*/ */
function get_all_xprofile_contributor_hours_teams() : array { function get_all_xprofile_contributor_hours_teams(): array {
global $wpdb; global $wpdb;
// This might need a `LIMIT` in the future as more users save values, but it's performant as of August 2022. // This might need a `LIMIT` in the future as more users save values, but it's performant as of August 2022.
@ -163,7 +163,7 @@ function get_aggregate_contributor_data_for_pledge( $pledge_id ) {
'teams' => array(), 'teams' => array(),
); );
$aggregate_data = array_reduce( $data, function( $carry, $item ) { $aggregate_data = array_reduce( $data, function ( $carry, $item ) {
switch ( $item['field_id'] ) { switch ( $item['field_id'] ) {
case FIELD_IDS['hours_per_week']: case FIELD_IDS['hours_per_week']:
$carry['hours'] += absint( $item['value'] ); $carry['hours'] += absint( $item['value'] );
@ -179,7 +179,7 @@ function get_aggregate_contributor_data_for_pledge( $pledge_id ) {
}, $initial ); }, $initial );
$aggregate_data['teams'] = array_map( $aggregate_data['teams'] = array_map(
function( $team ) { function ( $team ) {
// Fix for renamed team. // Fix for renamed team.
if ( 'Theme Review Team' === $team ) { if ( 'Theme Review Team' === $team ) {
$team = 'Themes Team'; $team = 'Themes Team';
@ -235,7 +235,7 @@ function get_contributor_user_data( $user_id ) {
* This deletes directly from the database and object cache -- rather than using something like * This deletes directly from the database and object cache -- rather than using something like
* `BP_XProfile_Field::delete()` -- because w.org/5 runs on a different network than profiles.w.org. * `BP_XProfile_Field::delete()` -- because w.org/5 runs on a different network than profiles.w.org.
*/ */
function reset_contribution_data( $user_id ) : void { function reset_contribution_data( $user_id ): void {
global $wpdb; global $wpdb;
$wpdb->query( $wpdb->prepare( ' $wpdb->query( $wpdb->prepare( '

View file

@ -1,8 +1,8 @@
<?php <?php
use function WordPressDotOrg\FiveForTheFuture\Stats\{ get_snapshot_data };
use WordPressDotOrg\FiveForTheFuture\{ Contributor }; use WordPressDotOrg\FiveForTheFuture\{ Contributor };
use WordPressDotOrg\FiveForTheFuture\Tests\Helpers as TestHelpers; use WordPressDotOrg\FiveForTheFuture\Tests\Helpers as TestHelpers;
use function WordPressDotOrg\FiveForTheFuture\Stats\{ get_snapshot_data };
defined( 'WPINC' ) || die(); defined( 'WPINC' ) || die();
@ -45,7 +45,7 @@ class Test_Stats extends WP_UnitTestCase {
/** /**
* @covers WordPressDotOrg\FiveForTheFuture\Stats\get_snapshot_data * @covers WordPressDotOrg\FiveForTheFuture\Stats\get_snapshot_data
*/ */
public function test_get_snapshot() : void { public function test_get_snapshot(): void {
// Setup 2 company-sponsored contributors. // Setup 2 company-sponsored contributors.
$jane = self::$users['jane']; $jane = self::$users['jane'];
$ashish = self::$users['ashish']; $ashish = self::$users['ashish'];