Gateway   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 93
Duplicated Lines 9.68 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 9
lcom 1
cbo 4
dl 9
loc 93
ccs 27
cts 30
cp 0.9
rs 10
c 1
b 0
f 1

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 7 1
A setUrl() 0 4 1
A setMerchantID() 0 4 1
A setAccessCode() 0 4 1
A purchase() 0 5 1
A send() 0 5 1
A getData() 9 10 1
A charge() 0 6 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;
4
5
use GuzzleHttp\Client;
6
use PHPieces\ANZGateway\enums\FormFields\MerchantFields;
7
8
class Gateway
9
{
10
11
	/**
12
	 * @param Client
13
	 */
14
	private $client;
15
16
17
	/**
18
	 *
19
	 * @var String
20
	 */
21
	private $merchantID;
22
23
24
	/**
25
	 *
26
	 * @var String
27
	 */
28
	private $merchantAccessCode;
29
30
	/**
31
	 * @var string
32
	 */
33
	private $url;
34
35
36
	/**
37
	 *
38
	 * @var array
39
	 */
40
	private $data = [];
41
42 9
	public function __construct(Client $client, $url = 'https://migs.mastercard.com.au/vpcdps')
43
	{
44 9
		$this->client = $client;
45 9
		$this->url = $url;
46 9
	}
47
48 3
	public static function create() : self
49
	{
50
51 3
		return new self(new Client([
52 3
			'base_uri' => 'https://migs.mastercard.com.au/vpcdps',
53
		]));
54
	}
55
56
	public function setUrl(string $url) : void 
57
	{
58
		$this->url = $url;
59
	}
60
61 3
	public function setMerchantID(string $id) : void
62
	{
63 3
		$this->merchantID = $id;
64 3
	}
65
66 3
	public function setAccessCode(string $code) : void
67
	{
68 3
		$this->merchantAccessCode = $code;
69 3
	}
70
71 3
	public function purchase(array $data) : self
72
	{
73 3
		$this->data = $data;
74 3
		return $this;
75
	}
76
77 3
	public function send() : Charge
78
	{
79 3
		$request = ChargeRequest::create($this->getData());
80 3
		return $this->charge($request);
81
	}
82
83 3 View Code Duplication
	private function getData() : 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...
84
	{
85 3
		return array_merge(
86 3
			$this->data,
87
			[
88 3
				MerchantFields::MERCHANT_ID         => $this->merchantID,
89 3
				MerchantFields::MERCHANT_ACCESSCODE => $this->merchantAccessCode,
90
			]
91
		);
92
	}
93
94 6
	public function charge(ChargeRequest $charge) : Charge
95
	{
96 6
		$response = $this->client->request('POST', $this->url, ['form_params' => $charge->toArray()]);
97
98 6
		return new Charge($response->getBody()->getContents());
99
	}
100
}
101