Encrypt   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 57.69 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 15
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A doRun() 15 15 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Tools\CryptTool;
12
13
/**
14
 * Encrypt the stdin with the given @privateKey for the given @publicKey
15
 * @package Threema\Console\Command
16
 */
17
class Encrypt extends Base {
18
	public function __construct() {
19
		parent::__construct('Encrypt',
20
			array(self::argPrivateKey, self::argPublicKey),
21
			'Encrypt standard input using the given sender private key and recipient public key. two lines to standard output: first the nonce (hex), and then the box (hex).');
22
	}
23
24
	/**
25
	 * run the command
26
	 */
27 View Code Duplication
	protected function doRun() {
0 ignored issues
show
Duplication introduced by
This method 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...
28
		$privateKey = $this->getArgumentPrivateKey(self::argPrivateKey);
29
		$publicKey = $this->getArgumentPublicKey(self::argPublicKey);
30
		$textToEncrypt = $this->readStdIn();
31
		Common::required($privateKey, $publicKey, $textToEncrypt);
32
33
		$cryptTool = CryptTool::getInstance();
34
		//create a random nonce
35
		$newNonce = $cryptTool->randomNonce();
36
		$encryptedMessageText = $cryptTool->encryptMessageText($textToEncrypt, $privateKey, $publicKey, $newNonce);
37
38
		Common::ln($cryptTool->bin2hex($newNonce));
39
		//output encrypted text
40
		Common::ln($cryptTool->bin2hex($encryptedMessageText));
41
	}
42
}
43