Completed
Push — master ( f0b491...11ee78 )
by Thomas
09:37
created

KeekoPackageSchema::parse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
crap 2
1
<?php
2
namespace keeko\core\schema;
3
4
use phootwork\collection\Map;
5
6
abstract class KeekoPackageSchema extends SubSchema {
7
8
	/** @var string */
9
	protected $title;
10
	
11
	/** @var string */
12 2
	protected $class;
13 2
	
14
	/** @var Map<string, Map> */
15
	protected $extensions;
16
	
17
	/** @var Map<string, string> */
18
	protected $extensionPoints;
19
	
20
	/**
21 2
	 * @param array $contents
22 2
	 */
23
	protected function parse($contents = []) {
24
		$data = new Map($contents);
25
	
26
		$this->title = $data->get('title', '');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
27
		$this->class = $data->get('class', '');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
28
		$this->extensions = $data->get('extensions', new Map());
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
29
		$this->extensionPoints = $data->get('extension-points', new Map());
30
		
31
		return $data;
32
	}
33
	
34
	public function toArray() {
35
		$arr = [
36
			'title' => $this->title,
37
			'class' => $this->class
38
		];
39
	
40
		$extensionPoints = $this->extensionPoints->toArray();
41
		if (count($extensionPoints) > 0) {
42
			$arr['extension-points'] = $extensionPoints;
43
		}
44
	
45
		$extensions = $this->extensions->toArray();
46
		if (count($extensions) > 0) {
47
			$arr['extensions'] = $extensions;
48
		}
49
50
		return $arr;
51
	}
52
	
53
	public function getTitle() {
54
		return $this->title;
55
	}
56
	
57
	public function setTitle($title) {
58
		$this->title = $title;
59
		return $this;
60
	}
61
	
62
	public function getClass() {
63
		return $this->class;
64
	}
65
	
66
	public function setClass($class) {
67
		$this->class = $class;
68
		return $this;
69
	}
70
	
71
	/**
72
	 * Checks whether an extension with the given key exists
73
	 *
74
	 * @param string $key
75
	 * @return boolean
76
	 */
77
	public function hasExtension($key) {
78
		return $this->extensions->has($key);
79
	}
80
	
81
	/**
82
	 * Returns the extension with the key
83
	 *
84
	 * @param string $key
85
	 * @return mixed
86
	 */
87
	public function getExtension($key) {
88
		return $this->extensions->get($key);
89
	}
90
	
91
	/**
92
	 * Returns all extensions
93
	 *
94
	 * @return Map
95
	 */
96
	public function getExtensions() {
97
		return $this->extensions;
98
	}
99
	
100
	/**
101
	 * Checks whether an extension point with the given key exists
102
	 *
103
	 * @param string $key
104
	 * @return boolean
105
	 */
106
	public function hasExtensionPoint($key) {
107
		return $this->extensionPoints->has($key);
108
	}
109
	
110
	/**
111
	 * Returns the path of the schema for the given key
112
	 *
113
	 * @param string $key
114
	 * @return string
115
	 */
116
	public function getExtensionPoint($key) {
117
		return $this->extensionPoints->get($key);
118
	}
119
	
120
	/**
121
	 * Returns all extension points
122
	 *
123
	 * @return Map
124
	 */
125
	public function getExtensionPoints() {
126
		return $this->extensionPoints;
127
	}
128
}