Request   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 56
ccs 28
cts 30
cp 0.9333
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getUrl() 0 18 2
A getSign() 0 4 1
A getSignString() 0 16 2
1
<?php
2
3
namespace PaySys\CardPay\Security;
4
5
use Nette\Http\Url;
6
use PaySys\CardPay\Configuration;
7
use PaySys\CardPay\Payment;
8
9
10 1
final class Request
11
{
12
	const SERVER_TEST = "https://moja.tatrabanka.sk/cgi-bin/e-commerce/start/example";
13
	const SERVER_PRODUCTION = "https://moja.tatrabanka.sk/cgi-bin/e-commerce/start/cardpay";
14
15
	/** @var Configuration */
16
	protected $config;
17
18
19
	public function __construct(Configuration $config)
20
	{
21 1
		$this->config = $config;
22 1
	}
23
24
	public function getUrl(Payment $payment) : Url
25
	{
26 1
		$s = $this->getSign($payment);
0 ignored issues
show
Unused Code introduced by
$s is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
27 1
		$url = new Url(constant("self::SERVER_" . strtoupper($this->config->getMode())));
28 1
		$url->appendQuery('MID=' . $this->config->getMid())
29 1
			->appendQuery('AMT=' . $payment->getAmount())
30 1
			->appendQuery('CURR=' . $payment->getCurrency())
31 1
			->appendQuery('VS=' . $payment->getVariableSymbol())
32 1
			->appendQuery('RURL=' . $this->config->getRurl())
33 1
			->appendQuery('IPC=' . $this->config->getIpc())
34 1
			->appendQuery('NAME=' . $payment->getName());
35 1
		if ($payment->getTpay()) {
36
			$url->appendQuery('TPAY=Y');
37
		}
38 1
		$url->appendQuery('TIMESTAMP=' . $payment->getTimestamp())
39 1
			->appendQuery('HMAC=' . $this->getSign($payment));
40 1
		return $url;
41
	}
42
43
	public function getSign(Payment $payment) : string
44
	{
45 1
		return hash_hmac("sha256", $this->getSignString($payment), $this->config->getKey());
46
	}
47
48
	public function getSignString(Payment $payment) : string
49
	{
50 1
		$s = $this->config->getMid()
51 1
			. $payment->getAmount()
52 1
			. $payment->getCurrency()
53 1
			. $payment->getVariableSymbol()
54 1
			. $this->config->getRurl()
55 1
			. $this->config->getIpc()
56 1
			. $payment->getName();
57 1
		if ($payment->getTpay()) {
58
			$s .= 'Y';
59
		}
60 1
		$s .= $this->config->getRem()
61 1
			. $payment->getTimestamp();
62 1
		return $s;
63
	}
64
65
}
66