Completed
Pull Request — master (#6)
by Guilh
02:50
created

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