Completed
Push — develop ( 129ec6...18b59a )
by Reüel
09:53
created

Statuses::transform()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 10
ccs 0
cts 8
cp 0
rs 10
cc 3
nc 3
nop 1
crap 12
1
<?php
2
/**
3
 * Statuses
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2020 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Sisow;
12
13
use Pronamic\WordPress\Pay\Payments\PaymentStatus as Core_Statuses;
14
15
/**
16
 * Title: Sisow statuses constants
17
 * Description:
18
 * Copyright: 2005-2020 Pronamic
19
 * Company: Pronamic
20
 *
21
 * @author  Reüel van der Steege
22
 * @version 2.0.4
23
 * @since   2.0.1
24
 */
25
class Statuses {
26
	/**
27
	 * Open.
28
	 *
29
	 * @var string
30
	 */
31
	const OPEN = 'Open';
32
33
	/**
34
	 * Pending.
35
	 *
36
	 * @var string
37
	 */
38
	const PENDING = 'Pending';
39
40
	/**
41
	 * Reservation.
42
	 *
43
	 * @var string
44
	 */
45
	const RESERVATION = 'Reservation';
46
47
	/**
48
	 * Paid.
49
	 *
50
	 * @var string
51
	 */
52
	const SUCCESS = 'Success';
53
54
	/**
55
	 * Cancelled.
56
	 *
57
	 * @var string
58
	 */
59
	const CANCELLED = 'Cancelled';
60
61
	/**
62
	 * Expired.
63
	 *
64
	 * @var string
65
	 */
66
	const EXPIRED = 'Expired';
67
68
	/**
69
	 * Denied.
70
	 *
71
	 * @var string
72
	 */
73
	const DENIED = 'Denied';
74
75
	/**
76
	 * Failure.
77
	 *
78
	 * @var string
79
	 */
80
	const FAILURE = 'Failure';
81
82
	/**
83
	 * Reversed.
84
	 *
85
	 * @var string
86
	 */
87
	const REVERSED = 'Reversed';
88
89
	/**
90
	 * Statuses map.
91
	 *
92
	 * @var array<string,string>
93
	 */
94
	private static $map = array(
95
		self::CANCELLED   => Core_Statuses::CANCELLED,
96
		self::DENIED      => Core_Statuses::FAILURE,
97
		self::EXPIRED     => Core_Statuses::EXPIRED,
98
		self::FAILURE     => Core_Statuses::FAILURE,
99
		self::OPEN        => Core_Statuses::OPEN,
100
		self::PENDING     => Core_Statuses::OPEN,
101
		self::RESERVATION => Core_Statuses::RESERVED,
102
		self::REVERSED    => Core_Statuses::REFUNDED,
103
		self::SUCCESS     => Core_Statuses::SUCCESS,
104
	);
105
106
	/**
107
	 * Transform an Sisow state to a more global status.
108
	 *
109
	 * @param string $status Sisow status.
110
	 *
111
	 * @return string|null Pay status.
112
	 */
113
	public static function transform( $status ) {
114
		if ( ! is_scalar( $status ) ) {
1 ignored issue
show
introduced by
The condition is_scalar($status) is always true.
Loading history...
115
			return null;
116
		}
117
118
		if ( isset( self::$map[ $status ] ) ) {
119
			return self::$map[ $status ];
120
		}
121
122
		return null;
123
	}
124
}
125