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

OutputFacade::addModules()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

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