Completed
Push — master ( e2ac37...21f028 )
by Jeroen De
03:38
created

ElementJsonSerializer::titleAndText()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 4
nop 1
crap 3
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\Presentation;
6
7
8
use Maps\Elements\BaseElement;
9
10
class ElementJsonSerializer {
11
12
	private $parser;
13
14 20
	public function __construct( WikitextParser $parser ) {
15 20
		$this->parser = $parser;
16 20
	}
17
18 5
	public function wikitextToHtml( BaseElement $element ): array {
19 5
		$json = $element->getArrayValue();
20
21 5
		$this->titleAndText( $json );
22
23 5
		return $json;
24
	}
25
26 19
	public function titleAndText( array &$elementJson ) {
27 19
		$elementJson['title'] = $this->parser->wikitextToHtml( $elementJson['title'] );
28 19
		$elementJson['text'] = $this->parser->wikitextToHtml( $elementJson['text'] );
29
30 19
		$hasTitleAndText = $elementJson['title'] !== '' && $elementJson['text'] !== '';
31 19
		$elementJson['text'] = ( $hasTitleAndText ? '<b>' . $elementJson['title'] . '</b><hr />' : $elementJson['title'] ) . $elementJson['text'];
32 19
		$elementJson['title'] = strip_tags( $elementJson['title'] );
33 19
	}
34
35
}