Tag::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
namespace gossi\swagger;
3
4
use gossi\swagger\parts\DescriptionPart;
5
use gossi\swagger\parts\ExtensionPart;
6
use gossi\swagger\parts\ExternalDocsPart;
7
use phootwork\collection\CollectionUtils;
8
use phootwork\lang\Arrayable;
9
10
class Tag extends AbstractModel implements Arrayable {
11
12
	use DescriptionPart;
13
	use ExternalDocsPart;
14
	use ExtensionPart;
15
16
	/** @var string */
17
	private $name;
18
19
	private $isObject = true;
20
21 1
	public function __construct($contents = []) {
22 1
		$this->parse($contents);
23 1
	}
24
25 1
	private function parse($contents = []) {
26 1
		if (is_string($contents)) {
27 1
			$this->isObject = false;
28 1
			$this->name = $contents;
29 1
		} else {
30
			$data = CollectionUtils::toMap($contents);
31
32
			$this->isObject = true;
33
			$this->name = $data->get('name');
34
35
			// parts
36
			$this->parseDescription($data);
37
			$this->parseExternalDocs($data);
38
			$this->parseExtensions($data);
39
		}
40 1
	}
41
42
	public function toArray() {
43
		return $this->export('name', 'description', 'externalDocs');
44
	}
45
46 1
	public function isObject() {
47 1
		return $this->isObject;
48
	}
49
50
	public function setObject($object) {
51
		$this->isObject = $object;
52
	}
53
54
	/**
55
	 *
56
	 * @return string
57
	 */
58 1
	public function getName() {
59 1
		return $this->name;
60
	}
61
62
	/**
63
	 *
64
	 * @param string $name
65
	 */
66
	public function setName($name) {
67
		$this->name = $name;
68
		return $this;
69
	}
70
71
}
72