@@ -292,9 +292,11 @@ public function get_next_badge_id() {
292292 * @return int
293293 */
294294 public function get_next_badges_excess_points () {
295- $ excess_points = 0 ;
296- $ next_1_badge_points = 0 ;
297- $ next_2_badge_points = 0 ;
295+ $ next_1_badge_points = 0 ;
296+ $ next_2_badge_points = 0 ;
297+ $ badge_1_excess_points = 0 ;
298+ $ badge_2_excess_points = 0 ;
299+
298300 // Get the next badge object.
299301 $ next_1_badge = self ::get_instance_from_id ( $ this ->get_next_badge_id () );
300302 if ( $ next_1_badge ) {
@@ -306,9 +308,21 @@ public function get_next_badges_excess_points() {
306308 }
307309 }
308310
309- $ excess_points = \max ( 0 , $ next_1_badge_points - self ::TARGET_POINTS );
310- $ excess_points += \max ( 0 , $ next_2_badge_points - 2 * self ::TARGET_POINTS );
311+ // If the $next_1_badge has more than 10 points, calculate the excess points.
312+ if ( $ next_1_badge_points > self ::TARGET_POINTS ) {
313+ $ badge_1_excess_points = \max ( 0 , $ next_1_badge_points - self ::TARGET_POINTS );
314+ }
315+
316+ // If the $next_2_badge has more than 10 points, calculate the excess points.
317+ if ( $ next_2_badge_points > self ::TARGET_POINTS ) {
318+ $ badge_2_excess_points = \max ( 0 , $ next_2_badge_points - self ::TARGET_POINTS );
319+
320+ // Does the $next_1_badge need more points to reach 10?
321+ if ( $ next_1_badge_points < self ::TARGET_POINTS ) {
322+ $ badge_2_excess_points = \max ( 0 , ( $ next_1_badge_points + $ badge_2_excess_points ) - self ::TARGET_POINTS );
323+ }
324+ }
311325
312- return (int ) $ excess_points ;
326+ return (int ) $ badge_1_excess_points + ( int ) $ badge_2_excess_points ;
313327 }
314328}
0 commit comments