Util   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 3
eloc 28
c 4
b 0
f 0
dl 0
loc 86
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A filter() 0 2 1
A get_pattern() 0 34 2
1
<?php
2
/**
3
 * Util
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2022 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Payments
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Sisow;
12
13
/**
14
 * Title: Sisow utility class
15
 * Description:
16
 * Copyright: 2005-2022 Pronamic
17
 * Company: Pronamic
18
 *
19
 * @author  Remco Tolsma
20
 * @version 2.0.0
21
 * @since   1.0.0
22
 */
23
class Util {
24
	/**
25
	 * Holds the unhallowed character pattern.
26
	 *
27
	 * @var string|null
28
	 */
29
	private static $pattern;
30
31
	/**
32
	 * Get unhallowed character pattern.
33
	 *
34
	 * Karakterset
35
	 *
36
	 * @link http://pronamic.nl/wp-content/uploads/2013/02/sisow-rest-api-v3.2.1.pdf
37
	 *
38
	 * Hieronder de tabel toegestane karakters.
39
	 *
40
	 * Karakter(s)  Omschrijving
41
	 * A-Z          Hoofdletters
42
	 * a-z          Kleine letters
43
	 * 0-9          Cijfers
44
	 * =            Is/gelijk
45
	 *              Spatie
46
	 * %            Procent
47
	 * *            Asterisk
48
	 * +            Plus
49
	 * -            Min
50
	 * .            Punt
51
	 * /            Slash
52
	 * &            Ampersand
53
	 * @            Apestaart
54
	 * "            Dubbel quote
55
	 * '            Enkele quote
56
	 * :            Dubbele punt
57
	 * ;            Punt komma
58
	 * ?            Vraagteken
59
	 * (            Haakje openen
60
	 * )            Haakje sluiten
61
	 * $            Dollar
62
	 *
63
	 * @return string
64
	 */
65 1
	public static function get_pattern() {
66 1
		if ( null === self::$pattern ) {
67
			$characters = array(
68 1
				'A-Z',
69
				'a-z',
70
				'0-9',
71
				'=',
72
				' ',
73
				'%',
74
				'*',
75
				'+',
76
				'-',
77
				'.',
78
				'/',
79
				'&',
80
				'@',
81
				'"',
82
				'\'',
83
				':',
84
				';',
85
				'?',
86
				'(',
87
				')',
88
				'$',
89
			);
90
91
			/*
92
			 * We use a # as a regex delimiter instead of a / so we don't have to escape the slash.
93
			 * @link http://stackoverflow.com/q/12239424
94
			 */
95 1
			self::$pattern = '#[^' . implode( $characters ) . ']#';
96
		}
97
98 1
		return self::$pattern;
99
	}
100
101
	/**
102
	 * Filter all Sisow unhallowed characters.
103
	 *
104
	 * @param string $string String to filter.
105
	 * @return mixed
106
	 */
107 1
	public static function filter( $string ) {
108 1
		return preg_replace( self::get_pattern(), '', $string );
109
	}
110
}
111