SendE2E::getParams()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * @author Threema GmbH
4
 * @copyright Copyright (c) 2015-2016 Threema GmbH
5
 */
6
7
8
namespace Threema\MsgApi\Commands;
9
10
use Threema\MsgApi\Commands\CommandInterface;
11
use Threema\MsgApi\Commands\Results\SendE2EResult;
12
use Threema\MsgApi\Tools\CryptTool;
13
14
class SendE2E implements CommandInterface {
15
	/**
16
	 * @var string
17
	 */
18
	private $nonce;
19
20
	/**
21
	 * @var string
22
	 */
23
	private $box;
24
25
	/**
26
	 * @var string
27
	 */
28
	private $threemaId;
29
30
	/**
31
	 * @param string $threemaId
32
	 * @param string $nonce
33
	 * @param string $box
34
	 */
35
	public function __construct($threemaId, $nonce, $box) {
36
		$this->nonce = $nonce;
37
		$this->box = $box;
38
		$this->threemaId = $threemaId;
39
	}
40
41
	/**
42
	 * @return string
43
	 */
44
	public function getNonce() {
45
		return $this->nonce;
46
	}
47
48
	/**
49
	 * @return string
50
	 */
51
	public function getBox() {
52
		return $this->box;
53
	}
54
55
	/**
56
	 * @return array
57
	 */
58
	public function getParams() {
59
		$cryptTool = CryptTool::getInstance();
60
61
		$p['to'] = $this->threemaId;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$p was never initialized. Although not strictly required by PHP, it is generally a good practice to add $p = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
62
		$p['nonce'] = $cryptTool->bin2hex($this->getNonce());
63
		$p['box'] = $cryptTool->bin2hex($this->getBox());
64
		return $p;
65
	}
66
67
	/**
68
	 * @return string
69
	 */
70
	public function getPath() {
71
		return 'send_e2e';
72
	}
73
74
	/**
75
	 * @param int $httpCode
76
	 * @param object $res
77
	 * @return SendE2EResult
78
	 */
79
	public function parseResult($httpCode, $res){
80
		return new SendE2EResult($httpCode, $res);
81
	}
82
}
83