ConvertAddresses   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 52
ccs 18
cts 24
cp 0.75
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hordeToString() 0 3 1
A hordeToAssoc() 0 6 1
A hordeListToStringArray() 0 7 2
A hordeListToAssocArray() 0 7 2
A convertAddressList() 0 7 2
1
<?php
2
3
/**
4
 * @author Christoph Wurst <[email protected]>
5
 *
6
 * Mail
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace OCA\Mail\Model;
23
24
use Horde_Imap_Client_Data_Envelope;
25
use Horde_Mail_Rfc822_List;
26
use Horde_Mail_Rfc822_Address;
27
28
trait ConvertAddresses {
29
30 6
	private function hordeToString(Horde_Mail_Rfc822_Address $address) {
31 6
		return $address->writeAddress();
32
	}
33
34 7
	private function hordeToAssoc(Horde_Mail_Rfc822_Address $address) {
35
		return [
36 7
			'label' => $address->label,
37 7
			'email' => $address->bare_address,
38 7
		];
39
	}
40
41
	/**
42
	 * Convert horde mail address list to array of strings
43
	 *
44
	 * @param Horde_Mail_Rfc822_List $list
45
	 * @return string[]
46
	 */
47 12
	protected function hordeListToStringArray(Horde_Mail_Rfc822_List $list) {
48 12
		$addresses = [];
49 12
		foreach ($list as $address) {
50 6
			$addresses[] = $this->hordeToString($address);
51 12
		}
52 12
		return $addresses;
53
	}
54
55
	/**
56
	 * @param Horde_Mail_Rfc822_List $list
57
	 * @return array
58
	 */
59
	protected function hordeListToAssocArray(Horde_Mail_Rfc822_List $list) {
60
		$addresses = [];
61
		foreach ($list as $address) {
62
			$addresses[] = $this->hordeToAssoc($address);
63
		}
64
		return $addresses;
65
	}
66
67
	/**
68
	 * @param Horde_Imap_Client_Data_Envelope|Horde_Mail_Rfc822_List $envelope
69
	 * @return array
70
	 */
71 7
	protected function convertAddressList($envelope) {
72 7
		$list = [];
73 7
		foreach ($envelope as $t) {
74 7
			$list[] = $this->hordeToAssoc($t);
75 7
		}
76 7
		return $list;
77
	}
78
79
}
80