Completed
Push — master ( 84bb38...eab4fc )
by Jeroen De
03:59
created

OutputFacade   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 53.85%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 0
dl 0
loc 55
ccs 14
cts 26
cp 0.5385
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A newFromOutputPage() 0 5 1
A newFromParserOutput() 0 5 1
A addHtml() 0 9 3
A addModules() 0 9 3
A addHeadItem() 0 9 3
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\Presentation;
6
7
use OutputPage;
8
use ParserOutput;
9
10
class OutputFacade {
11
12
	/**
13
	 * @var OutputPage
14
	 */
15
	private $outputPage;
16
17
	/**
18
	 * @var ParserOutput
19
	 */
20
	private $parserOutput;
21
22
	public static function newFromOutputPage( OutputPage $outputPage ) {
23
		$instance = new self();
24
		$instance->outputPage = $outputPage;
25
		return $instance;
26
	}
27
28 4
	public static function newFromParserOutput( ParserOutput $parserOutput ) {
29 4
		$instance = new self();
30 4
		$instance->parserOutput = $parserOutput;
31 4
		return $instance;
32
	}
33
34 4
	public function addHtml( string $html ) {
35 4
		if ( $this->outputPage !== null ) {
36
			$this->outputPage->addHTML( $html );
37
		}
38
39 4
		if ( $this->parserOutput !== null ) {
40 4
			$this->parserOutput->setText( $this->parserOutput->getRawText() . $html );
41
		}
42 4
	}
43
44 4
	public function addModules( string ...$modules ) {
45 4
		if ( $this->outputPage !== null ) {
46
			$this->outputPage->addModules( $modules );
47
		}
48
49 4
		if ( $this->parserOutput !== null ) {
50 4
			$this->parserOutput->addModules( $modules );
51
		}
52 4
	}
53
54
	public function addHeadItem( string $name, string $html ) {
55
		if ( $this->outputPage !== null ) {
56
			$this->outputPage->addHeadItem( $name, $html );
57
		}
58
59
		if ( $this->parserOutput !== null ) {
60
			$this->parserOutput->addHeadItem( $html, $name );
61
		}
62
	}
63
64
}
65