Test Setup Failed
Push — develop ( c0da3f...b920e1 )
by Remco
05:14
created

Currency::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 0
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * Currency
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2021 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Money
9
 */
10
11
namespace Pronamic\WordPress\Money;
12
13
use JsonSerializable;
14
15
/**
16
 * Currency
17
 *
18
 * @author  Remco Tolsma
19
 * @version 1.2.5
20
 * @since   1.0.0
21
 */
22
class Currency implements JsonSerializable {
23
	/**
24
	 * Alphabetic code.
25
	 *
26
	 * @var string|null
27
	 */
28
	private $alphabetic_code;
29
30
	/**
31
	 * Numeric code.
32
	 *
33
	 * @var string|null
34
	 */
35
	private $numeric_code;
36
37
	/**
38
	 * Symbol.
39
	 *
40
	 * @var string|null
41
	 */
42
	private $symbol;
43
44
	/**
45
	 * Name.
46
	 *
47
	 * @var string|null
48
	 */
49
	private $name;
50
51
	/**
52
	 * Number decimals.
53
	 *
54
	 * @var int
55
	 */
56
	private $number_decimals;
57
58
	/**
59 95
	 * Construct and initialize currency object.
60 95
	 */
61 95
	public function __construct() {
62
		$this->set_number_decimals( 2 );
63
	}
64
65
	/**
66
	 * Get alphabetic code.
67
	 *
68 14
	 * @return string|null
69 14
	 */
70
	public function get_alphabetic_code() {
71
		return $this->alphabetic_code;
72
	}
73
74
	/**
75
	 * Set alphabetic code.
76
	 *
77
	 * @param string|null $alphabetic_code Alphabetic code.
78 1
	 * @return void
79 1
	 */
80 1
	public function set_alphabetic_code( $alphabetic_code ) {
81
		$this->alphabetic_code = $alphabetic_code;
82
	}
83
84
	/**
85
	 * Get numeric code.
86
	 *
87
	 * @return string|null
88
	 */
89
	public function get_numeric_code() {
90
		return $this->numeric_code;
91
	}
92
93
	/**
94
	 * Set numeric code.
95
	 *
96
	 * @param string|null $numeric_code Numeric code.
97 1
	 * @return void
98 1
	 */
99 1
	public function set_numeric_code( $numeric_code ) {
100
		$this->numeric_code = $numeric_code;
101
	}
102
103
	/**
104
	 * Get symbol.
105
	 *
106 14
	 * @return string|null
107 14
	 */
108
	public function get_symbol() {
109
		return $this->symbol;
110
	}
111
112
	/**
113
	 * Set symbol.
114
	 *
115
	 * @param string|null $symbol Symbol.
116 1
	 * @return void
117 1
	 */
118 1
	public function set_symbol( $symbol ) {
119
		$this->symbol = $symbol;
120
	}
121
122
	/**
123
	 * Get number decimals.
124
	 *
125 35
	 * @return int
126 35
	 */
127
	public function get_number_decimals() {
128
		return $this->number_decimals;
129
	}
130
131
	/**
132
	 * Set number decimals.
133
	 *
134
	 * @param int $number_decimals Number of decimals.
135 95
	 * @return void
136 95
	 */
137 95
	final public function set_number_decimals( $number_decimals ) {
138
		$this->number_decimals = intval( $number_decimals );
139
	}
140
141
	/**
142
	 * Get instance.
143
	 *
144
	 * @param string $alphabetic_code Alphabetic code.
145
	 *
146 95
	 * @return Currency
147 95
	 */
148
	public static function get_instance( $alphabetic_code ) {
149
		return Currencies::get_currency( $alphabetic_code );
150
	}
151
152
	/**
153
	 * Get name.
154
	 *
155
	 * @return string|null
156
	 */
157
	public function get_name() {
158
		return $this->name;
159
	}
160
161
	/**
162
	 * Set name.
163
	 *
164
	 * @param string|null $name Currency name.
165 1
	 * @return void
166 1
	 */
167 1
	public function set_name( $name ) {
168
		$this->name = $name;
169
	}
170
171
	/**
172
	 * JSON serialize.
173
	 * 
174
	 * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php
175
	 * @return string
176
	 */
177
	public function jsonSerialize() {
178
		return $this->alphabetic_code;
179
	}
180
}
181