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

ElementJsonSerializer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A wikitextToHtml() 0 7 1
A titleAndText() 0 8 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
}