Transactions   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 96
Duplicated Lines 36.46 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 7
c 5
b 1
f 0
lcom 1
cbo 1
dl 35
loc 96
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getTransaction() 0 7 1
A getTransactionsForAccountId() 11 11 1
A addAnnotationForTransaction() 12 12 2
A removeAnnotationForTransaction() 12 12 2

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 Thepixeldeveloper\Mondo\Client;
4
5
use Thepixeldeveloper\Mondo\ClientInterface;
6
use Thepixeldeveloper\Mondo\Response;
7
8
class Transactions
9
{
10
    /**
11
     * Mondo client.
12
     *
13
     * @var ClientInterface
14
     */
15
    protected $client;
16
17
    /**
18
     * Accounts constructor.
19
     *
20
     * @param ClientInterface $client
21
     */
22
    public function __construct(ClientInterface $client)
23
    {
24
        $this->client = $client;
25
    }
26
27
    /**
28
     * Information for a given transaction ID.
29
     *
30
     * @param string $transactionId
31
     *
32
     * @return Response\Transactions\Transaction
33
     */
34
    public function getTransaction($transactionId)
35
    {
36
        return $this->client->deserializeResponse(
37
            $this->client->get('/transactions/' . $transactionId),
38
            Response\Transactions\Transaction::class
39
        );
40
    }
41
42
    /**
43
     * Get the transaction history for the account id.
44
     *
45
     * @param string $accountId
46
     *
47
     * @return Response\Transactions
48
     */
49 View Code Duplication
    public function getTransactionsForAccountId($accountId)
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...
50
    {
51
        return $this->client->deserializeResponse(
52
            $this->client->get('/transactions', [
53
                'query' => [
54
                    'account_id' => $accountId
55
                ]
56
            ]),
57
            Response\Transactions::class
58
        );
59
    }
60
61
    /**
62
     * Add annotation(s) for a transaction.
63
     *
64
     * @param string       $transactionId
65
     * @param string|array $key
66
     * @param string       $value
67
     *
68
     * @return \Psr\Http\Message\ResponseInterface
69
     */
70 View Code Duplication
    public function addAnnotationForTransaction($transactionId, $key, $value = null)
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
        if (is_string($key)) {
73
            $metadata = [$key => $value];
74
        } else {
75
            $metadata = $key;
76
        }
77
78
        return $this->client->get('/transactions/' . $transactionId, [
79
            'body' => ['metadata' => $metadata],
80
        ]);
81
    }
82
83
    /**
84
     * Remove annotation(s) for a transaction.
85
     *
86
     * @param string $transactionId
87
     * @param string $keys
88
     *
89
     * @return \Psr\Http\Message\ResponseInterface
90
     */
91 View Code Duplication
    public function removeAnnotationForTransaction($transactionId, $keys)
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...
92
    {
93
        if (is_string($keys)) {
94
            $keys = [$keys];
95
        }
96
97
        $keys = array_flip($keys);
98
99
        return $this->client->get('/transactions/' . $transactionId, [
100
            'body' => ['metadata' => $keys],
101
        ]);
102
    }
103
}
104