Validator::isCurrency()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 1
cts 1
cp 1
cc 2
eloc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace PaySys\TatraPay;
4
5
use Nette\Utils\Validators;
6
7
8 1
class Validator
9
{
10
11
	public static function isAmount($s) : bool
12
	{
13 1
		return (is_string($s) && preg_match('/^\d{1,9}(\.\d{1,2})?$/', $s));
14
	}
15
16
	public static function isVariableSymbol($s) : bool
17
	{
18 1
		return (is_string($s) && preg_match('/^\d{1,10}$/', $s));
19
	}
20
21
	public static function isCurrency($s) : bool
22
	{
23 1
		return (is_string($s) && $s === '978');
24
	}
25
26
	public static function isLang($s) : bool
27
	{
28 1
		return (is_string($s) && in_array($s, [
29 1
			'sk',
30
			'en',
31
		]));
32
	}
33
34
	public static function isMid($s) : bool
35
	{
36 1
		return (is_string($s) && preg_match('/^\d{3,4}$/', $s));
37
	}
38
39
	public static function isKey($s) : bool
40
	{
41 1
		$hex = '[0-9a-f]{2}';
42 1
		return (is_string($s) && preg_match('/^(.{64}|.{128}|(' . $hex . ':){63}' . $hex . ')$/', $s));
43
	}
44
45
	public static function isRurl($s) : bool
46
	{
47 1
		return (is_string($s) && Validators::isUri($s));
48
	}
49
50
	public static function isTimestamp($s) : bool
51
	{
52
		return (
53 1
			is_string($s) &&
54 1
			preg_match('/^\d{14}$/', $s) &&
55 1
			\DateTime::createFromFormat('dmYHis', $s, new \DateTimeZone('UTC')) instanceof \DateTime &&
56 1
			$s === \DateTime::createFromFormat('dmYHis', $s, new \DateTimeZone('UTC'))->format('dmYHis')
57
		);
58
	}
59
60
}
61