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

Formatter::format()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 6
cp 0
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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