Request::getUrl()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2.0023

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
ccs 11
cts 12
cp 0.9167
cc 2
eloc 13
nc 2
nop 1
crap 2.0023
1
<?php
2
3
namespace PaySys\TatraPay\Security;
4
5
use Nette\Http\Url;
6
use PaySys\TatraPay\Configuration;
7
use PaySys\TatraPay\Payment;
8
9
10 1
final class Request
11
{
12
	const SERVER = "https://moja.tatrabanka.sk/cgi-bin/e-commerce/start/tatrapay";
13
14
	/** @var Configuration */
15
	protected $config;
16
17
18
	public function __construct(Configuration $config)
19
	{
20 1
		$this->config = $config;
21 1
	}
22
23
	public function getUrl(Payment $payment) : Url
24
	{
25 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...
26 1
		$url = new Url(self::SERVER);
27 1
		$url->appendQuery('MID=' . $this->config->getMid())
28 1
			->appendQuery('AMT=' . $payment->getAmount())
29 1
			->appendQuery('CURR=' . $payment->getCurrency())
30 1
			->appendQuery('VS=' . $payment->getVariableSymbol())
31 1
			->appendQuery('RURL=' . $this->config->getRurl());
32 1
		if (!empty($this->config->getRem()))
33
			$url->appendQuery('REM=' . $this->config->getRem());
34 1
		$url->appendQuery('TIMESTAMP=' . $payment->getTimestamp())
35 1
			->appendQuery('HMAC=' . $this->getSign($payment));
36 1
		return $url;
37
	}
38
39
	public function getSign(Payment $payment) : string
40
	{
41 1
		return hash_hmac("sha256", $this->getSignString($payment), $this->config->getKey());
42
	}
43
44
	public function getSignString(Payment $payment) : string
45
	{
46 1
		return $this->config->getMid()
47 1
			. $payment->getAmount()
48 1
			. $payment->getCurrency()
49 1
			. $payment->getVariableSymbol()
50 1
			. $this->config->getRurl()
51 1
			. $this->config->getRem()
52 1
			. $payment->getTimestamp();
53
	}
54
55
}
56