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

Contact::parse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 6
nc 1
nop 1
crap 1
1
<?php
2
namespace gossi\swagger;
3
4
use gossi\swagger\parts\ExtensionPart;
5
use gossi\swagger\util\MergeHelper;
6
use phootwork\collection\CollectionUtils;
7
use phootwork\lang\Arrayable;
8
9
class Contact extends AbstractModel implements Arrayable {
10
11
	use ExtensionPart;
12
13
	/** @var string */
14
	private $name;
15
16
	/** @var string */
17
	private $url;
18
19
	/** @var string */
20
	private $email;
21 10
22 10
	public function __construct($contents = []) {
23 10
		$this->parse($contents);
24
	}
25 10
26 10
	private function parse($contents = []) {
27
		$data = CollectionUtils::toMap($contents);
28 10
29 10
		$this->name = $data->get('name');
30 10
		$this->url = $data->get('url');
31
		$this->email = $data->get('email');
32
33 10
		// extensions
34 10
		$this->parseExtensions($data);
35
	}
36 7
37 7
	/**
38
	 * {@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
		MergeHelper::mergeFields($this->name, $model->name, $overwrite);
42
		MergeHelper::mergeFields($this->url, $model->url, $overwrite);
43
		MergeHelper::mergeFields($this->email, $model->email, $overwrite);
44 1
45 1
		$this->mergeExtensions($model, $overwrite);
46
	}
47
48
	public function toArray() {
49
		return $this->export('name', 'url', 'email');
50
	}
51
52
	/**
53 1
	 *
54 1
	 * @return string
55 1
	 */
56
	public function getName() {
57
		return $this->name;
58
	}
59
60
	/**
61
	 *
62 1
	 * @param string $name
63 1
	 * @return $this
64
	 */
65
	public function setName($name) {
66
		$this->name = $name;
67
		return $this;
68
	}
69
70
	/**
71 1
	 *
72 1
	 * @return string
73 1
	 */
74
	public function getUrl() {
75
		return $this->url;
76
	}
77
78
	/**
79
	 *
80 1
	 * @param string $url
81 1
	 * @return $this
82
	 */
83
	public function setUrl($url) {
84
		$this->url = $url;
85
		return $this;
86
	}
87
88
	/**
89 1
	 *
90 1
	 * @return string
91 1
	 */
92
	public function getEmail() {
93
		return $this->email;
94
	}
95
96
	/**
97
	 *
98
	 * @param string $email
99
	 * @return $this
100
	 */
101
	public function setEmail($email) {
102
		$this->email = $email;
103
		return $this;
104
	}
105
106
}
107