Transactions::addAnnotationForTransaction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 12
loc 12
rs 9.4285
cc 2
eloc 7
nc 2
nop 3
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