Completed
Push — master ( fef961...cb7bad )
by Thomas
01:47
created

Formatter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 28
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 4
A format() 0 12 1
1
<?php
2
namespace gossi\formatter;
3
4
use gossi\code\profiles\Profile;
5
use gossi\formatter\formatters\DelegateFormatter;
6
use gossi\formatter\parser\Parser;
7
8
class Formatter {
9
10
	/** @var Profile */
11
	private $profile;
12
13 2
	public function __construct($profile = null) {
14 2
		if (is_string($profile) || $profile === null) {
15 2
			$profile = new Profile($profile);
16
		}
17 2
		if (!($profile instanceof Profile)) {
18
			throw new \InvalidArgumentException('$profile must be a string or instanceof gossi\code\profiles\Profile');
19
		}
20 2
		$this->profile = $profile;
21 2
	}
22
23 2
	public function format($code) {
24 2
		$parser = new Parser();
25 2
		$parser->parse($code);
26
27
		// formatting
28 2
		$delegate = new DelegateFormatter($parser, $this->profile);
29 2
		$delegate->format();
30
31
		// post processing
32
33 2
		return $delegate->getCode();
34
	}
35
}
36