Merchant   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 11.27 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 8
loc 71
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A validate() 0 11 4
A toArray() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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