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

Formatter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 30.76%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
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)) {
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