Fix non-numeric errors in PHP 7.1

This commit is contained in:
Brian Miyaji
2017-01-15 10:01:25 +11:00
parent 896741ccb8
commit da12f410fb
6 changed files with 31 additions and 10 deletions

View File

@@ -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;

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -101,6 +101,7 @@ if ( ! isset( $class ) ) $class = null;
endif;
if ( 'text' !== $format ) {
$value = floatval( $value );
$totals[ $key ] += $value;
}

View File

@@ -139,6 +139,7 @@ if ( ! isset( $subs ) ) $subs = array();
endif;
if ( 'number' === $format ) {
$value = floatval( $value );
$totals[ $key ] += $value;
}