AutoCompleteService::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
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\Service\AutoCompletion;
23
24
use OCA\Mail\Service\ContactsIntegration;
25
26
class AutoCompleteService {
27
28
	/** @var ContactsIntegration */
29
	private $contactsIntegration;
30
31
	/** @var AddressCollector */
32
	private $addressCollector;
33
34 1
	public function __construct(ContactsIntegration $ci, AddressCollector $ac) {
35 1
		$this->contactsIntegration = $ci;
36 1
		$this->addressCollector = $ac;
37 1
	}
38
39 1
	public function findMatches($term) {
40 1
		$recipientsFromContacts = $this->contactsIntegration->getMatchingRecipient($term);
41 1
		$fromCollector = $this->addressCollector->searchAddress($term);
42
43
		// Convert collected addresses into same format as CI creates
44 1
		$recipientsFromCollector = array_map(function ($address) {
45
			return [
46 1
				'id' => $address->getId(),
47 1
				'label' => $address->getEmail(),
48 1
				'value' => $address->getEmail(),
49 1
			];
50 1
		}, $fromCollector);
51
52 1
		return array_merge($recipientsFromContacts, $recipientsFromCollector);
53
	}
54
55
}
56