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

Formatter::__construct()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4.0466

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 7
cp 0.8571
rs 9.9666
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 4.0466
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