Completed
Pull Request — master (#6)
by Guilh
04:05
created

Header   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 5
c 3
b 1
f 0
lcom 1
cbo 7
dl 0
loc 39
ccs 15
cts 15
cp 1
rs 10
1
<?php
2
namespace gossi\swagger;
3
4
use gossi\swagger\parts\DescriptionPart;
5
use gossi\swagger\parts\ExtensionPart;
6
use gossi\swagger\parts\ItemsPart;
7
use gossi\swagger\parts\TypePart;
8
use phootwork\collection\CollectionUtils;
9
use phootwork\collection\Map;
10
use phootwork\lang\Arrayable;
11
12
class Header extends AbstractModel implements Arrayable {
13
14
	use DescriptionPart;
15
	use TypePart;
16
	use ItemsPart;
17
	use ExtensionPart;
18
19
	/** @var string */
20
	private $header;
21
22 1
	public function __construct($header, $contents = []) {
23 1
		$this->header = $header;
24 1
		$this->parse($contents);
25 1
	}
26
27 1
	private function parse($contents = []) {
28 1
		$data = CollectionUtils::toMap($contents);
29
30
		// parts
31 1
		$this->parseDescription($data);
32 1
		$this->parseType($data);
33 1
		$this->parseItems($data);
34 1
		$this->parseExtensions($data);
35 1
	}
36
37 1
	/**
38 1
	 * {@inheritdoc}
39
	 */
40
	public function merge(static $model, $overwrite = false) {
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STATIC, expecting T_VARIABLE
Loading history...
41
		if ($this->header !== $model->header) {
42
			throw new \InvalidArgumentException(sprintf('You can\'t merge two different headers (provided "%s" and "%s").', $this->header, $model->header));
43
		}
44
45
		$this->mergeDescription($model, $overwrite);
46 1
		$this->mergeType($model, $overwrite);
47 1
		$this->mergeItems($model, $overwrite);
48
		$this->mergeExtensions($model, $overwrite);
49
	}
50
51
	public function toArray() {
52
		return $this->export('description', $this->getTypeExportFields(), 'items');
53
	}
54
55
	/**
56
	 * Returns the header
57
	 *
58
	 * @return string
59
	 */
60
	public function getHeader() {
61
		return $this->header;
62
	}
63
64
}
65