Merchant::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
crap 1
1
<?php
2
3
namespace PHPieces\ANZGateway\models;
4
5
use PHPieces\ANZGateway\enums\FormFields\MerchantFields;
6
use PHPieces\ANZGateway\exceptions\InvalidMerchantDetails;
7
8
class Merchant extends Model
9
{
10
    protected static $fields = MerchantFields::class;
11
12
    /**
13
     * You need to log into the MA site to obtain this value. This
14
     * value will be different for test and live transactions. This
15
     * should be located in a configuration file or extracted from
16
     * a database.
17
     * @var String
18
     */
19
    private $merchantAccessCode;
20
21
    /**
22
     * This is a required field and may have
23
     * a maximum of 40 alpha numeric characters. This
24
     * reference should be unique for each transaction attempt
25
     * and is used for the Query DR function. This field label is
26
     * Merchant Transaction Reference in the Sample Code.
27
     *
28
     * @var String
29
     */
30
    private $merchantTransactionReference;
31
32
    /**
33
     * Your Merchant ID is supplied in your Welcome Email.
34
     *
35
     * @var String
36
     */
37
    private $merchantID;
38
39 12
    public function __construct(
40
        string $merchantAccessCode,
41
        string $merchantTransactionReference,
42
        string $merchantID
43
    ) {
44
    
45 12
        $this->validate($merchantAccessCode, $merchantTransactionReference, $merchantID);
46 9
        $this->merchantAccessCode = (string) $merchantAccessCode;
47 9
        $this->merchantTransactionReference = (string) $merchantTransactionReference;
48 9
        $this->merchantID = (string) $merchantID;
49 9
    }
50
51
    /**
52
     *
53
     * @param String $merchantAccessCode
54
     * @param String $merchantTransactionReference
55
     * @param String $merchantID
56
     * @throws InvalidMerchantDetails
57
     */
58 12
    private function validate(
59
        string $merchantAccessCode,
60
        string $merchantTransactionReference,
61
        string $merchantID
62
    ) : void {
63
    
64 12
        if (empty($merchantAccessCode) || empty($merchantTransactionReference) || empty($merchantID)
65
        ) {
66 3
            throw new InvalidMerchantDetails("Missing merchant details");
67
        }
68 9
    }
69
70 6 View Code Duplication
    public function toArray() : array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
71
    {
72
        return [
73 6
            MerchantFields::MERCHANT_ACCESSCODE            => $this->merchantAccessCode,
74 6
            MerchantFields::MERCHANT_TRANSACTION_REFERENCE => $this->merchantTransactionReference,
75 6
            MerchantFields::MERCHANT_ID                    => $this->merchantID
76
        ];
77
    }
78
}
79