Completed
Push — move ( 889447...795827 )
by Jeroen De
05:20
created

BaseElement   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 67.74%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 1
dl 0
loc 66
ccs 21
cts 31
cp 0.6774
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setTitle() 0 3 1
A setText() 0 3 1
A setLink() 0 3 1
A getArrayValue() 0 3 1
A getJSONObject() 0 9 4
A getText() 0 3 1
A getTitle() 0 3 1
A getLink() 0 3 1
A getOptions() 0 3 1
A setOptions() 0 3 1
1
<?php
2
3
namespace Maps\Elements;
4
5
use Maps\ElementOptions;
6
7
/**
8
 * @since 3.0
9
 *
10
 * @licence GNU GPL v2+
11
 * @author Kim Eik < [email protected] >
12
 * @author Jeroen De Dauw < [email protected] >
13
 */
14
abstract class BaseElement {
15
16
	/**
17
	 * @var ElementOptions
18
	 */
19
	protected $options;
20
21 73
	public function __construct() {
22 73
		$this->options = new ElementOptions();
23 73
	}
24
25 8
	public function setTitle( string $title ) {
26 8
		$this->options->setOption( 'title', trim( $title ) );
27 8
	}
28
29 5
	public function setText( string $text ) {
30 5
		$this->options->setOption( 'text', trim( $text ) );
31 5
	}
32
33
	public function setLink( string $link ) {
34
		$this->options->setOption( 'link', $link );
35
	}
36
37 5
	public function getArrayValue() {
38 5
		return $this->getJSONObject();
0 ignored issues
show
Deprecated Code introduced by
The method Maps\Elements\BaseElement::getJSONObject() has been deprecated.

This method has been deprecated.

Loading history...
39
	}
40
41
	/**
42
	 * @deprecated
43
	 *
44
	 * @param string $defText
45
	 * @param string $defTitle
46
	 *
47
	 * @return array
48
	 */
49 18
	public function getJSONObject( string $defText = '', string $defTitle = '' ): array {
50 18
		$array = [];
51
52 18
		$array['text'] = $this->options->hasOption( 'text' ) ? $this->getText() : $defText;
53 18
		$array['title'] = $this->options->hasOption( 'title' ) ? $this->getTitle() : $defTitle;
54 18
		$array['link'] = $this->options->hasOption( 'link' ) ? $this->getLink() : '';
55
56 18
		return $array;
57
	}
58
59 5
	public function getText(): string {
60 5
		return $this->options->getOption( 'text' );
61
	}
62
63 8
	public function getTitle(): string {
64 8
		return $this->options->getOption( 'title' );
65
	}
66
67
	public function getLink(): string {
68
		return $this->options->getOption( 'link' );
69
	}
70
71
	public function getOptions(): ElementOptions {
72
		return $this->options;
73
	}
74
75
	public function setOptions( ElementOptions $options ) {
76
		$this->options = $options;
77
	}
78
79
}
80