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

TrackingCode   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 53
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A from_id() 0 3 1
A jsonSerialize() 0 3 1
A __toString() 0 3 1
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