Payment::getCurrency()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 1
cts 1
cp 1
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace PaySys\TatraPay;
4
5
use PaySys\PaySys\IPayment;
6
7
8 1
class Payment implements IPayment
9
{
10
	/** @var string */
11
	protected $amt;
12
13
	/** @var string */
14
	protected $vs;
15
16
	/** @var string */
17
	protected $curr = '978'; // EUR
18
19
	/** @var string */
20
	protected $timestamp;
21
22
23
	public function __construct(string $amt, string $vs)
24
	{
25 1
		$this->setAmount($amt);
26 1
		$this->setVariableSymbol($vs);
27 1
		$this->timestamp = gmdate('dmYHis');
28 1
	}
29
30
	public function setAmount($amt) : IPayment
31
	{
32 1
		if (!Validator::isAmount($amt))
33 1
			throw new \PaySys\PaySys\InvalidArgumentException(sprintf("Amount must have maximal 9 digits before dot and maximal 2 digits after. '%s' is invalid.", $amt));
34
35 1
		$this->amt = $amt;
36 1
		return $this;
37
	}
38
39
	public function getAmount() : string
40
	{
41 1
		return $this->amt;
42
	}
43
44
	public function setVariableSymbol(string $vs) : Payment
45
	{
46 1
		if (!Validator::isVariableSymbol($vs))
47 1
			throw new \PaySys\PaySys\InvalidArgumentException(sprintf("Variable symbol must have minimal 1 and maximal 10 digits. '%s' is invalid.", $vs));
48
49 1
		$this->vs = $vs;
50 1
		return $this;
51
	}
52
53
	public function getVariableSymbol() : string
54
	{
55 1
		return $this->vs;
56
	}
57
58
	public function getCurrency() : string
59
	{
60 1
		return $this->curr;
61
	}
62
63
	/**
64
	 * @internal
65
	 */
66
	public function setTimestamp(string $timestamp) : Payment
67
	{
68 1
		if (!Validator::isTimestamp($timestamp))
69
			throw new \PaySys\PaySys\InvalidArgumentException(sprintf("Timestamp '%s' is invalid.", $timestamp));
70
71 1
		$this->timestamp = $timestamp;
72 1
		return $this;
73
	}
74
75
	public function getTimestamp() : string
76
	{
77 1
		return $this->timestamp;
78
	}
79
80
81
	private static function normalizeCurrency(string $curr) : string
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
82
	{
83
		$curr2code = [
84
			'EUR' => '978',
85
		];
86
87
		return $curr2code[strtoupper($curr)] ?? $curr;
88
	}
89
}
90