Format   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getLocale() 0 5 3
A load() 0 7 1
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\Module;
8
/** Module for loading a formatter with a locale */
9
class Format implements \Transphporm\Module {
10
	private $locale;
11
12
	public function __construct($locale = null) {
13
		$this->locale = $locale;
14
	}
15
16
	private function getLocale() {
17
		if (is_array($this->locale)) return $this->locale;
18
		else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true);
19
		else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true);
20
	}
21
22
	public function load(\Transphporm\Config $config) {
23
		$locale = $this->getLocale();
24
		$config->registerFormatter(new \Transphporm\Formatter\Number($locale));
25
		$config->registerFormatter(new \Transphporm\Formatter\Date($locale));
26
		$config->registerFormatter(new \Transphporm\Formatter\StringFormatter());
27
		$config->registerFormatter(new \Transphporm\Formatter\Nl2brFormat());
28
	}
29
}
30