LookupIdByPhoneNo::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
dl 6
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * @author Threema GmbH
4
 * @copyright Copyright (c) 2015-2016 Threema GmbH
5
 */
6
7
8
namespace Threema\Console\Command;
9
10
use Threema\Console\Common;
11
use Threema\MsgApi\Connection;
12
use Threema\MsgApi\ConnectionSettings;
13
use Threema\MsgApi\PublicKeyStore;
14
15 View Code Duplication
class LookupIdByPhoneNo extends Base {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
	const argPhoneNo = 'phoneNo';
17
18
	/**
19
	 * @var PublicKeyStore
20
	 */
21
	private $publicKeyStore;
22
23
	/**
24
	 * @param PublicKeyStore $publicKeyStore
25
	 */
26
	public function __construct(PublicKeyStore $publicKeyStore) {
27
		parent::__construct('ID-Lookup By Phone Number',
28
			array(self::argPhoneNo, self::argFrom, self::argSecret),
29
			'Lookup the ID linked to the given phone number (will be hashed locally).');
30
		$this->publicKeyStore = $publicKeyStore;
31
	}
32
33
	protected function doRun() {
34
		$phoneNo = $this->getArgument(self::argPhoneNo);
35
		$from = $this->getArgumentThreemaId(self::argFrom);
36
		$secret = $this->getArgument(self::argSecret);
37
38
		Common::required($phoneNo, $from, $secret);
39
40
		//define connection settings
41
		$settings = new ConnectionSettings($from, $secret);
42
43
		//create a connection
44
		$connector = new Connection($settings, $this->publicKeyStore);
45
46
		$result = $connector->keyLookupByPhoneNumber($phoneNo);;
47
		Common::required($result);
48
		if($result->isSuccess()) {
49
			Common::l($result->getId());
50
		}
51
		else {
52
			Common::e($result->getErrorMessage());
53
		}
54
	}
55
}
56