Completed
Pull Request — develop (#1328)
by Naveen
03:29
created

Badge_Generator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A round_to_nearest_hundred() 0 10 2
A generate_html() 0 5 2
1
<?php
2
3
namespace Wordlift\Vocabulary\Menu\Badge;
4
5
6
/**
7
 * Class Badge_Generator
8
 * @since 3.30.0
9
 * @package Wordlift\Vocabulary\Menu\Badge
10
 */
11
class Badge_Generator {
12
13
	/**
14
	 * @param $number
15
	 *
16
	 * @return int
17
	 */
18
	public static function round_to_nearest_hundred( $number ) {
19
20
		$number = (int) $number;
21
22
		if ( $number < 100 ) {
23
			return $number;
24
		}
25
26
		return floor( $number / 100 ) * 100;
27
	}
28
29
	public static function generate_html( $number ) {
30
		$round = self::round_to_nearest_hundred( $number );
31
		$count_string = $round < 100 ? "$round" : "$round+";
32
		return "<span class=\"wl-admin-menu-badge\">$count_string</span>";
33
	}
34
35
36
}