TransactionSource   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 55
ccs 14
cts 14
cp 1
rs 10
c 1
b 1
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A validate() 0 10 3
A toArray() 0 7 1
1
<?php
2
3
namespace PHPieces\ANZGateway\models;
4
5
use PHPieces\ANZGateway\enums\FormFields\TransactionFields;
6
use PHPieces\ANZGateway\exceptions\InvalidArgumentException;
7
8
class TransactionSource extends Model
9
{
10
    protected static $fields = TransactionFields::class;
11
12
    private $type;
13
14
    /**
15
     * Only use this field if you are implementing an application
16
     * that mixes web shopping transactions and a phone order
17
     * system. You must discuss the use of this field with the ANZ
18
     * eGate team.
19
     *
20
     * @var string
21
     */
22
    private $subType;
23
24
    private $types = [
25
        "INTERNET"  => "Indicates an Internet transaction",
26
        "MAILORDER" => "Indicates a mail order transaction",
27
        "TELORDER"  => "Indicates a telephone order transaction",
28
    ];
29
    
30
    private $subTypes = [
31
        ""            => "No subtype",
32
        "SINGLE"      => "Indicates a single payment to complete order",
33
        "INSTALLMENT" => "Indicates an installment transaction",
34
        "RECURRING"   => "Indicates a recurring transaction",
35
    ];
36
37 15
    public function __construct(string $type = 'INTERNET', string $subType = '')
38
    {
39 15
        $this->type = (string) $type;
40 15
        $this->subType = (string) $subType;
41 15
        $this->validate();
42 9
    }
43
44 15
    public function validate() : void
45
    {
46 15
        if (!array_key_exists($this->type, $this->types)) {
47 3
            throw new InvalidArgumentException("invalid transaction type supplied");
48
        }
49
50 12
        if (!array_key_exists($this->subType, $this->subTypes)) {
51 3
            throw new InvalidArgumentException("Invalid transaction subtype supplied");
52
        }
53 9
    }
54
55 6
    public function toArray() : array
56
    {
57
        return [
58 6
            TransactionFields::TYPE_FIELD     => $this->type,
59 6
            TransactionFields::SUB_TYPE_FIELD => $this->subType
60
        ];
61
    }
62
}
63