Invoice   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 52.78 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 5
c 4
b 0
f 0
lcom 1
cbo 1
dl 38
loc 72
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A listInvoicesByCustomer() 19 19 2
A getInvoice() 19 19 2
A getInvoicePdf() 0 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
declare(strict_types=1);
3
4
namespace Zoho\Subscription\Api;
5
6
use Zoho\Subscription\Client\Client;
7
8
/**
9
 * @author Hang Pham <[email protected]>
10
 * @author Tristan Bessoussa <[email protected]>
11
 *
12
 * @link https://www.zoho.com/subscriptions/api/v1/#invoices
13
 */
14
class Invoice extends Client
15
{
16
    /**
17
     * @param string $customerId The customer's id
18
     *
19
     * @throws \Exception
20
     *
21
     * @return array
22
     */
23 View Code Duplication
    public function listInvoicesByCustomer(string $customerId): 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...
24
    {
25
        $cacheKey = sprintf('zoho_invoices_%s', $customerId);
26
        $hit = $this->getFromCache($cacheKey);
27
28
        if (false === $hit) {
29
            $response = $this->sendRequest('GET', sprintf('invoices?customer_id=%s', $customerId));
30
31
            $result = $this->processResponse($response);
32
33
            $invoices = $result['invoices'];
34
35
            $this->saveToCache($cacheKey, $invoices);
36
37
            return $invoices;
38
        }
39
40
        return $hit;
41
    }
42
43
    /**
44
     * @param string $invoiceId The invoice's id
45
     *
46
     * @throws \Exception
47
     *
48
     * @return array
49
     */
50 View Code Duplication
    public function getInvoice(string $invoiceId)
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...
51
    {
52
        $cacheKey = sprintf('zoho_invoice_%s', $invoiceId);
53
        $hit = $this->getFromCache($cacheKey);
54
55
        if (false === $hit) {
56
            $response = $this->sendRequest('GET', sprintf('invoices/%s', $invoiceId));
57
58
            $result = $this->processResponse($response);
59
60
            $invoice = $result['invoice'];
61
62
            $this->saveToCache($cacheKey, $invoice);
63
64
            return $invoice;
65
        }
66
67
        return $hit;
68
    }
69
70
    /**
71
     * @param string $invoiceId The invoice's id
72
     *
73
     * @throws \Exception
74
     *
75
     * @return array
76
     */
77
    public function getInvoicePdf(string $invoiceId)
78
    {
79
        $response = $this->sendRequest('GET', sprintf('invoices/%s', $invoiceId), [
80
            'query' => ['accept' => 'pdf'],
81
        ]);
82
83
        return $response;
84
    }
85
}
86