Credits   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A doRun() 0 21 2
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
class Credits 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('Get remaining credits',
26
			array(self::argFrom, self::argSecret),
27
			'Get the remaining credits');
28
		$this->publicKeyStore = $publicKeyStore;
29
	}
30
31
	protected function doRun() {
32
		$from = $this->getArgumentThreemaId(self::argFrom);
33
		$secret = $this->getArgument(self::argSecret);
34
35
		Common::required($from, $secret);
36
37
		//define connection settings
38
		$settings = new ConnectionSettings($from, $secret);
39
40
		//create a connection
41
		$connector = new Connection($settings, $this->publicKeyStore);
42
43
		$result = $connector->credits();
44
		Common::required($result);
45
		if($result->isSuccess()) {
46
			Common::l("remaining credits: ".$result->getCredits());
47
		}
48
		else {
49
			Common::e($result->getErrorMessage());
50
		}
51
	}
52
}
53