mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-04-21 10:33:44 +03:00
Apply coding standards
This commit is contained in:
parent
b86470575f
commit
ed490dfc26
|
@ -7,9 +7,9 @@ use WP_Error, WP_Post, WP_User;
|
||||||
|
|
||||||
defined( 'WPINC' ) || die();
|
defined( 'WPINC' ) || die();
|
||||||
|
|
||||||
const SLUG = 'contributor';
|
const SLUG = 'contributor';
|
||||||
const SLUG_PL = 'contributors';
|
const SLUG_PL = 'contributors';
|
||||||
const CPT_ID = FiveForTheFuture\PREFIX . '_' . SLUG;
|
const CPT_ID = FiveForTheFuture\PREFIX . '_' . SLUG;
|
||||||
const INACTIVITY_THRESHOLD_MONTHS = 3;
|
const INACTIVITY_THRESHOLD_MONTHS = 3;
|
||||||
|
|
||||||
add_action( 'init', __NAMESPACE__ . '\register_custom_post_type', 0 );
|
add_action( 'init', __NAMESPACE__ . '\register_custom_post_type', 0 );
|
||||||
|
@ -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 ) ) {
|
||||||
|
@ -747,12 +747,12 @@ function add_user_data_to_xprofile( array $xprofiles ) : array {
|
||||||
|
|
||||||
foreach ( $established_users as $user ) {
|
foreach ( $established_users as $user ) {
|
||||||
$full_user = array(
|
$full_user = array(
|
||||||
'user_id' => absint( $user->ID ),
|
'user_id' => absint( $user->ID ),
|
||||||
'user_login' => $user->user_login,
|
'user_login' => $user->user_login,
|
||||||
'user_email' => $user->user_email,
|
'user_email' => $user->user_email,
|
||||||
'user_registered' => intval( strtotime( $user->user_registered ) ),
|
'user_registered' => intval( strtotime( $user->user_registered ) ),
|
||||||
'hours_per_week' => $xprofiles[ $user->ID ]->hours_per_week,
|
'hours_per_week' => $xprofiles[ $user->ID ]->hours_per_week,
|
||||||
'user_nicename' => $user->user_nicename,
|
'user_nicename' => $user->user_nicename,
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( ! empty( $user->meta_keys ) ) {
|
if ( ! empty( $user->meta_keys ) ) {
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
||||||
|
@ -114,10 +114,10 @@ function prepare_xprofile_contribution_data( array $raw_data ) {
|
||||||
$field_keys_by_id = array_flip( FIELD_IDS );
|
$field_keys_by_id = array_flip( FIELD_IDS );
|
||||||
|
|
||||||
foreach ( $raw_data as $datum ) {
|
foreach ( $raw_data as $datum ) {
|
||||||
$user_id = $datum['user_id'];
|
$user_id = $datum['user_id'];
|
||||||
$prepared_data[ $user_id ]['user_id'] = $user_id;
|
$prepared_data[ $user_id ]['user_id'] = $user_id;
|
||||||
$field_key = $field_keys_by_id[ (int) $datum['field_id'] ];
|
$field_key = $field_keys_by_id[ (int) $datum['field_id'] ];
|
||||||
$field_value = maybe_unserialize( $datum['value'] );
|
$field_value = maybe_unserialize( $datum['value'] );
|
||||||
|
|
||||||
if ( ! isset( $prepared_data[ $user_id ]['sponsored'] ) ) {
|
if ( ! isset( $prepared_data[ $user_id ]['sponsored'] ) ) {
|
||||||
$prepared_data[ $user_id ]['sponsored'] = false;
|
$prepared_data[ $user_id ]['sponsored'] = false;
|
||||||
|
@ -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( '
|
||||||
|
|
|
@ -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,14 +45,14 @@ 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'];
|
||||||
$tenup = self::$pledges['10up'];
|
$tenup = self::$pledges['10up'];
|
||||||
$tenup_contributors = Contributor\add_pledge_contributors( $tenup->ID, array( $jane->user_login, $ashish->user_login ) );
|
$tenup_contributors = Contributor\add_pledge_contributors( $tenup->ID, array( $jane->user_login, $ashish->user_login ) );
|
||||||
$tenup_jane_id = $tenup_contributors[ $jane->user_login ];
|
$tenup_jane_id = $tenup_contributors[ $jane->user_login ];
|
||||||
$tenup_ashish_id = $tenup_contributors[ $ashish->user_login ];
|
$tenup_ashish_id = $tenup_contributors[ $ashish->user_login ];
|
||||||
|
|
||||||
wp_update_post( array(
|
wp_update_post( array(
|
||||||
'ID' => $tenup_jane_id,
|
'ID' => $tenup_jane_id,
|
||||||
|
@ -64,15 +64,15 @@ class Test_Stats extends WP_UnitTestCase {
|
||||||
) );
|
) );
|
||||||
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'company_sponsored_hours' => 75,
|
'company_sponsored_hours' => 75,
|
||||||
'self_sponsored_hours' => 16,
|
'self_sponsored_hours' => 16,
|
||||||
|
|
||||||
'team_company_sponsored_contributors' => array(
|
'team_company_sponsored_contributors' => array(
|
||||||
'Core Team' => 1,
|
'Core Team' => 1,
|
||||||
'Documentation Team' => 1,
|
'Documentation Team' => 1,
|
||||||
),
|
),
|
||||||
|
|
||||||
'team_self_sponsored_contributors' => array(
|
'team_self_sponsored_contributors' => array(
|
||||||
'Meta Team' => 2,
|
'Meta Team' => 2,
|
||||||
'Polyglots Team' => 1,
|
'Polyglots Team' => 1,
|
||||||
'Training Team' => 1,
|
'Training Team' => 1,
|
||||||
|
|
Loading…
Reference in a new issue