Completed
Push — master ( f4bdff...fef961 )
by Thomas
01:46
created

Formatter::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.7085

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 4
cts 7
cp 0.5714
rs 9.9666
c 0
b 0
f 0
cc 3
nc 4
nop 1
crap 3.7085
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)) {
15
			$profile = new Profile($profile);
16
		}
17 2
		if (!($profile instanceof Profile)) {
18 2
			throw new \InvalidArgumentException('$profile must be a string or instanceof gossi\code\profiles\Profile');
19
		}
20
		$this->profile = $profile;
21
	}
22
23
	public function format($code) {
24
		$parser = new Parser();
25
		$parser->parse($code);
26
27
		// formatting
28
		$delegate = new DelegateFormatter($parser, $this->profile);
29
		$delegate->format();
30
31
		// post processing
32
33
		return $delegate->getCode();
34
	}
35
}
36