From da12f410fb3e5a3aa2ee84f8aafc3e949ce7ab13 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Sun, 15 Jan 2017 10:01:25 +1100 Subject: [PATCH] Fix non-numeric errors in PHP 7.1 --- includes/class-sp-league-table.php | 21 +++++++++++++------ includes/class-sp-player-list.php | 6 ++++-- includes/class-sp-player.php | 6 ++++-- includes/class-sp-team.php | 6 ++++++ .../event-performance-table-combined.php | 1 + templates/event-performance-table.php | 1 + 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/includes/class-sp-league-table.php b/includes/class-sp-league-table.php index dad65591..d3faeca7 100644 --- a/includes/class-sp-league-table.php +++ b/includes/class-sp-league-table.php @@ -349,6 +349,10 @@ class SP_League_Table extends SP_Custom_Post{ else: if ( array_key_exists( $team_id, $totals ) && is_array( $totals[ $team_id ] ) && array_key_exists( $key . 'for', $totals[ $team_id ] ) ): + + // Get numeric value + $value = floatval( $value ); + $totals[ $team_id ][ $key . 'for' ] += $value; $totals[ $team_id ][ $key . 'for' . ( $e + 1 ) ] = $value; @@ -366,19 +370,23 @@ class SP_League_Table extends SP_Custom_Post{ foreach( $results as $other_team_id => $other_result ): if ( $other_team_id != $team_id && array_key_exists( $key . 'against', $totals[ $team_id ] ) ): - $totals[ $team_id ][ $key . 'against' ] += sp_array_value( $other_result, $key, 0 ); - $totals[ $team_id ][ $key . 'against' . ( $e + 1 ) ] = sp_array_value( $other_result, $key, 0 ); + + // Get numeric value of other team's result + $value = floatval( sp_array_value( $other_result, $key, 0 ) ); + + $totals[ $team_id ][ $key . 'against' ] += $value; + $totals[ $team_id ][ $key . 'against' . ( $e + 1 ) ] = $value; // Add to home or away stats if ( 0 === $i ): - $totals[ $team_id ][ $key . 'against_home' ] += sp_array_value( $other_result, $key, 0 ); + $totals[ $team_id ][ $key . 'against_home' ] += $value; else: - $totals[ $team_id ][ $key . 'against_away' ] += sp_array_value( $other_result, $key, 0 ); + $totals[ $team_id ][ $key . 'against_away' ] += $value; endif; // Add to venue stats if ( sp_is_home_venue( $team_id, $event->ID ) ): - $totals[ $team_id ][ $key . 'against_venue' ] += sp_array_value( $other_result, $key, 0 ); + $totals[ $team_id ][ $key . 'against_venue' ] += $value; endif; endif; endforeach; @@ -572,7 +580,8 @@ class SP_League_Table extends SP_Custom_Post{ $adjustment = sp_array_value( $adjustments, $team_id, array() ); if ( $adjustment != 0 ): - $placeholder += sp_array_value( $adjustment, $stat->post_name, 0 ); + $value = floatval( sp_array_value( $adjustment, $stat->post_name, 0 ) ); + $placeholder += $value; $placeholder = number_format( $placeholder, $stat->precision, '.', '' ); endif; endif; diff --git a/includes/class-sp-player-list.php b/includes/class-sp-player-list.php index c3670f21..b531079a 100644 --- a/includes/class-sp-player-list.php +++ b/includes/class-sp-player-list.php @@ -196,6 +196,7 @@ class SP_Player_List extends SP_Custom_Post { if ( is_array( $player_league_season_stats ) ): foreach ( $player_league_season_stats as $key => $value ): $current_value = sp_array_value( sp_array_value( $placeholders, $player_id, array() ), $key, 0 ); + $value = floatval( $value ); $placeholders[ $player_id ][ $key ] = $current_value + $value; endforeach; endif; @@ -303,6 +304,7 @@ class SP_Player_List extends SP_Custom_Post { endif; endforeach; elseif ( array_key_exists( $key, $totals[ $player_id ] ) ): + $value = floatval( $value ); $totals[ $player_id ][ $key ] += $value; endif; endforeach; @@ -384,7 +386,7 @@ class SP_Player_List extends SP_Custom_Post { // Add to total $value = sp_array_value( $totals[ $player_id ], $result_slug . 'for', 0 ); - $value += $team_result; + $value += floatval( $team_result ); $totals[ $player_id ][ $result_slug . 'for' ] = $value; // Add subset @@ -401,7 +403,7 @@ class SP_Player_List extends SP_Custom_Post { // Add to total $value = sp_array_value( $totals[ $player_id ], $result_slug . 'against', 0 ); - $value += $team_result; + $value += floatval( $team_result ); $totals[ $player_id ][ $result_slug . 'against' ] = $value; // Add subset diff --git a/includes/class-sp-player.php b/includes/class-sp-player.php index 4868919e..15fa63cc 100644 --- a/includes/class-sp-player.php +++ b/includes/class-sp-player.php @@ -335,6 +335,7 @@ class SP_Player extends SP_Custom_Post { foreach ( $player_performance as $key => $value ): if ( array_key_exists( $key, $totals ) ): + $value = floatval( $value ); $totals[ $key ] += $value; endif; endforeach; @@ -416,7 +417,7 @@ class SP_Player extends SP_Custom_Post { // Add to total $value = sp_array_value( $totals, $result_slug . 'for', 0 ); - $value += $team_result; + $value += floatval( $team_result ); $totals[ $result_slug . 'for' ] = $value; // Add subset @@ -432,7 +433,7 @@ class SP_Player extends SP_Custom_Post { // Add to total $value = sp_array_value( $totals, $result_slug . 'against', 0 ); - $value += $team_result; + $value += floatval( $team_result ); $totals[ $result_slug . 'against' ] = $value; // Add subset @@ -659,6 +660,7 @@ class SP_Player extends SP_Custom_Post { $totals = array(); foreach ( $merged as $season => $stats ) { foreach ( $stats as $key => $value ) { + $value = floatval( $value ); $totals[ $key ] = sp_array_value( $totals, $key, 0 ) + $value; } } diff --git a/includes/class-sp-team.php b/includes/class-sp-team.php index 593e115b..a69109a8 100644 --- a/includes/class-sp-team.php +++ b/includes/class-sp-team.php @@ -259,6 +259,9 @@ class SP_Team extends SP_Custom_Post { endforeach; else: + + $value = floatval( $value ); + if ( array_key_exists( $key . 'for', $totals ) ): $totals[ $key . 'for' ] += $value; $totals[ $key . 'for' . ( $e + 1 ) ] = $value; @@ -278,6 +281,9 @@ class SP_Team extends SP_Custom_Post { endif; else: if ( $key != 'outcome' ): + + $value = floatval( $value ); + if ( array_key_exists( $key . 'against', $totals ) ): $totals[ $key . 'against' ] += $value; $totals[ $key . 'against' . ( $e + 1 ) ] = $value; diff --git a/templates/event-performance-table-combined.php b/templates/event-performance-table-combined.php index dddc4066..f512bb2e 100644 --- a/templates/event-performance-table-combined.php +++ b/templates/event-performance-table-combined.php @@ -101,6 +101,7 @@ if ( ! isset( $class ) ) $class = null; endif; if ( 'text' !== $format ) { + $value = floatval( $value ); $totals[ $key ] += $value; } diff --git a/templates/event-performance-table.php b/templates/event-performance-table.php index 1f1d68d6..d62e1176 100644 --- a/templates/event-performance-table.php +++ b/templates/event-performance-table.php @@ -139,6 +139,7 @@ if ( ! isset( $subs ) ) $subs = array(); endif; if ( 'number' === $format ) { + $value = floatval( $value ); $totals[ $key ] += $value; }