Completed
Push — develop ( 72a91d...14a321 )
by
unknown
04:09 queued 12s
created

Badge_Generator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get_ui_count() 0 10 2
A generate_html() 0 4 1
A get_formatted_count_string() 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
	 * Returns the term count which needs to be shown on ui.
15
	 * @param $number
16
	 *
17
	 * @return int
18
	 */
19
	public static function get_ui_count( $number ) {
20
21
		$number = (int) $number;
22
23
		if ( $number < 100 ) {
24
			return $number;
25
		}
26
27
		return 100;
28
	}
29
30
	public static function generate_html( $number ) {
31
		$count_string = self::get_formatted_count_string( $number );
32
		return "<span class=\"wl-admin-menu-badge\">$count_string</span>";
33
	}
34
35
	/**
36
	 * @param $number
37
	 *
38
	 * @return string
39
	 */
40
	public static function get_formatted_count_string( $number ) {
41
		$round        = self::get_ui_count( $number );
42
43
		return $round < 100 ? "$round" : "$round+";
44
	}
45
46
47
}