Completed
Push — nophpunit ( 9a5068 )
by Jeroen De
05:11
created

BaseElement::getArrayValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Maps\Elements;
4
5
use Maps\Element;
6
use Maps\ElementOptions;
7
8
/**
9
 * Base class for objects implementing the @see Element interface.
10
 *
11
 * @since 3.0
12
 *
13
 * @licence GNU GPL v2+
14
 * @author Kim Eik < [email protected] >
15
 * @author Jeroen De Dauw < [email protected] >
16
 */
17
abstract class BaseElement implements Element {
18
19
	/**
20
	 * @var ElementOptions
21
	 */
22
	protected $options;
23
24
	public function __construct() {
25
		$this->options = new ElementOptions();
26
	}
27
28
	public function setTitle( string $title ) {
29
		$this->options->setOption( 'title', $title );
30
	}
31
32
	public function setText( string $text ) {
33
		$this->options->setOption( 'text', $text );
34
	}
35
36
	public function setLink( string $link ) {
37
		$this->options->setOption( 'link', $link );
38
	}
39
40
	public function getArrayValue() {
41
		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...
42
	}
43
44
	/**
45
	 * @deprecated
46
	 *
47
	 * @param string $defText
48
	 * @param string $defTitle
49
	 *
50
	 * @return array
51
	 */
52
	public function getJSONObject( string $defText = '', string $defTitle = '' ): array {
53
		$array = [];
54
55
		$array['text'] = $this->options->hasOption( 'text' ) ? $this->getText() : $defText;
56
		$array['title'] = $this->options->hasOption( 'title' ) ? $this->getTitle() : $defTitle;
57
		$array['link'] = $this->options->hasOption( 'link' ) ? $this->getLink() : '';
58
59
		return $array;
60
	}
61
62
	public function getText(): string {
63
		return $this->options->getOption( 'text' );
64
	}
65
66
	public function getTitle(): string {
67
		return $this->options->getOption( 'title' );
68
	}
69
70
	public function getLink(): string {
71
		return $this->options->getOption( 'link' );
72
	}
73
74 8
	public function getOptions(): ElementOptions {
75 8
		return $this->options;
76
	}
77
78 4
	public function setOptions( ElementOptions $options ) {
79 4
		$this->options = $options;
80 4
	}
81
82
}
83