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 LookupIdByEmail extends Base { |
|
|
|
|
16
|
|
|
const argEmail = 'email'; |
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 Email Address', |
28
|
|
|
array(self::argEmail, self::argFrom, self::argSecret), |
29
|
|
|
'Lookup the ID linked to the given email address (will be hashed locally).'); |
30
|
|
|
$this->publicKeyStore = $publicKeyStore; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
protected function doRun() { |
34
|
|
|
$email = $this->getArgument(self::argEmail); |
35
|
|
|
$from = $this->getArgumentThreemaId(self::argFrom); |
36
|
|
|
$secret = $this->getArgument(self::argSecret); |
37
|
|
|
|
38
|
|
|
Common::required($email, $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->keyLookupByEmail($email);; |
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
|
|
|
|
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.