Number   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A decimal() 0 4 2
A currency() 0 5 2
1
<?php
2
/* @description     Transformation Style Sheets - Revolutionising PHP templating    *
3
 * @author          Tom Butler [email protected]                                             *
4
 * @copyright       2017 Tom Butler <[email protected]> | https://r.je/                      *
5
 * @license         http://www.opensource.org/licenses/bsd-license.php  BSD License *
6
 * @version         1.2                                                             */
7
namespace Transphporm\Formatter;
8
class Number {
9
	private $locale;
10
11
	public function __construct($locale) {
12
		$this->locale = $locale;
13
	}
14
15
	public function decimal($num, $decimals) {
16
		if (!is_numeric($num)) return $num;
17
		return number_format((float)$num, $decimals, $this->locale['decimal_separator'], $this->locale['thousands_separator']);
18
	}
19
20
	public function currency($num) {
21
		$num = $this->decimal($num, $this->locale['currency_decimals']);
22
		if ($this->locale['currency_position'] === 'before') return $this->locale['currency'] . $num;
23
		else return $num . $this->locale['currency'];
24
	}
25
}
26