Passed
Push — main ( 061772...28b955 )
by Remco
07:49 queued 12s
created

TrackingCode::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Tracking Code
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2020 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\Payvision
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Payvision;
12
13
/**
14
 * Tracking Code
15
 *
16
 * @link    https://developers.acehubpaymentservices.com/v3.3/reference#payment-3-1
17
 * @author  Remco Tolsma
18
 * @version 1.0.0
19
 * @since   1.0.0
20
 */
21
class TrackingCode implements \JsonSerializable {
22
	/**
23
	 * Code.
24
	 *
25
	 * Your Unique Transaction Reference. Minimum length: 8 characters.
26
	 *
27
	 * @var string
28
	 */
29
	private $code;
30
31
	/**
32
	 * Construct and initialize tracking code.
33
	 *
34
	 * @param string $code Code.
35
	 * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
36
	 * @throws \InvalidArgumentException Throws exception if length of code is less than 8 characters.
37
	 */
38 3
	public function __construct( $code ) {
39 3
		if ( \strlen( $code ) < 8 ) {
40 1
			throw new \InvalidArgumentException( 'Minimum length: 8 characters.' );
41
		}
42
43 2
		$this->code = $code;
44 2
	}
45
46
	/**
47
	 * From ID.
48
	 *
49
	 * @param string|int $id ID.
50
	 * @return self
51
	 */
52 2
	public static function from_id( $id ) {
53 2
		return new self( \sprintf( '%08s', $id ) );
54
	}
55
56
	/**
57
	 * JSON serialize.
58
	 *
59
	 * @return string
60
	 */
61 2
	public function jsonSerialize() {
62 2
		return $this->code;
63
	}
64
65
	/**
66
	 * To string.
67
	 *
68
	 * @return string
69
	 */
70 2
	public function __toString() {
71 2
		return $this->code;
72
	}
73
}
74