Code Duplication    Length = 12-12 lines in 4 locations

src/ShortenNums.php 4 locations

@@ 75-86 (lines=12) @@
72
	 * @param int $precision Number of number after decimal point.
73
	 * @return string 	A string number formated as 1K-1.5K
74
	 */		
75
	public static function readableThousand($value, $precision = 1): string
76
	{
77
		$range = [999, 999999];
78
		$suffix = 'K';
79
		// Check if value is a valid integer and does not start with 0, and force user to pass value as string
80
		self::validateRange($value, $range);
81
82
		$clean_number = $value / self::$formats[$suffix];
83
		$formated_number = number_format($clean_number, config('shorten-nums.precision') ?? $precision);
84
85
		return (preg_match('/\\d\.0$/', $formated_number)) ? rtrim(rtrim($formated_number,'0'), '.').$suffix : $formated_number.$suffix;
86
	}
87
88
	/**
89
	 * Convert 1,000,000 place to 1M
@@ 93-104 (lines=12) @@
90
	 * @param  int|string $value
91
	 * @param int $precision Number of number after decimal point.
92
	 */
93
	public static function readableMillion($value, $precision = 1): string
94
	{
95
		$range = [999999, 999999999];
96
		$suffix = 'M';
97
		// Check if value is a valid integer and does not start with 0, and force user to pass value as string
98
		self::validateRange($value, $range);
99
100
		$clean_number = $value / self::$formats[$suffix];
101
		$formated_number = number_format($clean_number, config('shorten-nums.precision') ?? $precision);
102
103
		return (preg_match('/\\d\.0$/', $formated_number)) ? rtrim(rtrim($formated_number,'0'), '.').$suffix : $formated_number.$suffix;
104
	}
105
106
	/**
107
	 * Convert 1000,000,000 place to 1B
@@ 111-122 (lines=12) @@
108
	 * @param  int|string $value
109
	 * @param int $precision Number of number after decimal point.
110
	 */
111
	public static function readableBillion($value, $precision = 1): string
112
	{
113
		$range = [999999999, 999999999999];
114
		$suffix = 'B';
115
		// Check if value is a valid integer and does not start with 0, and force user to pass value as string
116
		self::validateRange($value, $range);
117
118
		$clean_number = $value / self::$formats[$suffix];
119
		$formated_number = number_format($clean_number, config('shorten-nums.precision') ?? $precision);
120
121
		return (preg_match('/\\d\.0$/', $formated_number)) ? rtrim(rtrim($formated_number,'0'), '.').$suffix : $formated_number.$suffix;  
122
	}
123
124
	/**
125
	 * Convert 1,000,000,000,000 place to 1T
@@ 129-140 (lines=12) @@
126
	 * @param  int|string $value
127
	 * @param int $precision Number of number after decimal point.
128
	 */
129
	public static function readableTrillion($value, $precision = 1): string
130
	{
131
		$range = [999999999999, 999899999999930];
132
		$suffix = 'T';
133
		// Check if value is a valid integer and does not start with 0, and force user to pass value as string
134
		self::validateRange($value, $range);
135
136
		$clean_number = $value / self::$formats[$suffix];
137
		$formated_number = number_format($clean_number, config('shorten-nums.precision') ?? $precision);
138
139
		return (preg_match('/\\d\.0$/', $formated_number)) ? rtrim(rtrim($formated_number,'0'), '.').$suffix : $formated_number.$suffix; 
140
	}
141
142
143
	/**