Receiver   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 85
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setToThreemaId() 0 4 1
A setToPhoneNo() 0 4 1
A setToEmail() 0 4 1
A setValue() 0 5 1
A getParams() 0 19 4
1
<?php
2
/**
3
 * @author Threema GmbH
4
 * @copyright Copyright (c) 2015-2016 Threema GmbH
5
 */
6
7
8
namespace Threema\MsgApi;
9
10
class Receiver {
11
	const TYPE_ID = 'to';
12
	const TYPE_PHONE = 'phone';
13
	const TYPE_EMAIL = 'email';
14
15
	/**
16
	 * @var string
17
	 */
18
	private $type = self::TYPE_ID;
19
20
	/**
21
	 * @var string
22
	 */
23
	private $value;
24
25
	/**
26
	 * @param string $value
27
	 * @param string $type
28
	 */
29
	public function __construct($value, $type = self::TYPE_ID) {
30
		$this->setValue($value, $type);
31
	}
32
33
	/**
34
	 * @param string $threemaId
35
	 * @return $this
36
	 */
37
	public function setToThreemaId($threemaId) {
38
		return $this->setValue($threemaId,
39
			self::TYPE_ID);
40
	}
41
42
	/**
43
	 * @param string $phoneNo
44
	 * @return $this
45
	 */
46
	public function setToPhoneNo($phoneNo) {
47
		return $this->setValue($phoneNo,
48
			self::TYPE_PHONE);
49
	}
50
51
	/**
52
	 * @param string $emailAddress
53
	 * @return $this
54
	 */
55
	public function setToEmail($emailAddress) {
56
		return $this->setValue($emailAddress,
57
			self::TYPE_EMAIL);
58
	}
59
60
	/**
61
	 * @param string $value
62
	 * @param string $type
63
	 * @return $this
64
	 */
65
	private function setValue($value, $type) {
66
		$this->value = $value;
67
		$this->type = $type;
68
		return $this;
69
	}
70
71
	/**
72
	 * @return array
73
	 * @throws \InvalidArgumentException
74
	 */
75
	public function getParams() {
76
		switch($this->type) {
77
			case self::TYPE_ID:
78
				$to = $this->type;
79
				$this->value = strtoupper(trim($this->value));
80
				break;
81
82
			case self::TYPE_EMAIL:
83
			case self::TYPE_PHONE:
84
				$to = $this->type;
85
				break;
86
			default:
87
				throw new \InvalidArgumentException();
88
		}
89
90
		return array(
91
			$to => $this->value
92
		);
93
	}
94
}
95