|
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 LookupPublicKeyById extends Base { |
|
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var PublicKeyStore |
|
18
|
|
|
*/ |
|
19
|
|
|
private $publicKeyStore; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @param PublicKeyStore $publicKeyStore |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct(PublicKeyStore $publicKeyStore) { |
|
25
|
|
|
parent::__construct('Fetch Public Key', |
|
26
|
|
|
array(self::argThreemaId, self::argFrom, self::argSecret), |
|
27
|
|
|
'Lookup the public key for the given ID.'); |
|
28
|
|
|
$this->publicKeyStore = $publicKeyStore; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
protected function doRun() { |
|
32
|
|
|
$id = $this->getArgumentThreemaId(self::argThreemaId); |
|
33
|
|
|
$from = $this->getArgumentThreemaId(self::argFrom); |
|
34
|
|
|
$secret = $this->getArgument(self::argSecret); |
|
35
|
|
|
|
|
36
|
|
|
Common::required($id, $from, $secret); |
|
37
|
|
|
|
|
38
|
|
|
//define connection settings |
|
39
|
|
|
$settings = new ConnectionSettings($from, $secret); |
|
40
|
|
|
|
|
41
|
|
|
//create a connection |
|
42
|
|
|
$connector = new Connection($settings, $this->publicKeyStore); |
|
43
|
|
|
|
|
44
|
|
|
$result = $connector->fetchPublicKey($id); |
|
45
|
|
|
if($result->isSuccess()) { |
|
46
|
|
|
Common::l(Common::convertPublicKey($result->getPublicKey())); |
|
47
|
|
|
} |
|
48
|
|
|
else { |
|
49
|
|
|
Common::e($result->getErrorMessage()); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
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.