IssuedInvoiceFullyPay   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 85
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 85
loc 85
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 16 16 3
A getModelClass() 4 4 1
A getHttpMethod() 4 4 1
A getUri() 10 10 2
A getGuzzleOptions() 4 4 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 Fousky\Component\iDoklad\Functions\IssuedInvoices;
4
5
use Fousky\Component\iDoklad\Functions\iDokladAbstractFunction;
6
use Fousky\Component\iDoklad\Model\Void\BooleanModel;
7
8
/**
9
 * @see https://app.idoklad.cz/developer/Help/v2/cs/Api?apiId=PUT-api-v2-IssuedInvoices-id-FullyPay_dateOfPayment_salesPosEquipmentId
10
 *
11
 * @author Lukáš Brzák <[email protected]>
12
 */
13 View Code Duplication
class IssuedInvoiceFullyPay extends iDokladAbstractFunction
0 ignored issues
show
Duplication introduced by
This class 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...
14
{
15
    /** @var string $id */
16
    protected $id;
17
18
    /** @var array $urlParts */
19
    protected $urlParts;
20
21
    /**
22
     * @param string         $id
23
     * @param null|\DateTime $dateOfPayment
24
     * @param null|int       $salesPosEquipmentId
25
     */
26
    public function __construct(
27
        string $id,
28
        \DateTime $dateOfPayment = null,
29
        int $salesPosEquipmentId = null
30
    ) {
31
        $this->id = $id;
32
33
        $parts = [];
34
        if ($dateOfPayment) {
35
            $parts['dateOfPayment'] = $dateOfPayment->format('Y-m-d H:i:s');
36
        }
37
        if ($salesPosEquipmentId) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $salesPosEquipmentId of type null|integer is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
38
            $parts['salesPosEquipmentId'] = $salesPosEquipmentId;
39
        }
40
        $this->urlParts = $parts;
41
    }
42
43
    /**
44
     * Get iDokladModelInterface class.
45
     *
46
     * @see iDokladModelInterface
47
     *
48
     * @return string
49
     */
50
    public function getModelClass(): string
51
    {
52
        return BooleanModel::class;
53
    }
54
55
    /**
56
     * GET|POST|PUT|DELETE e.g.
57
     *
58
     * @see iDoklad::request()
59
     *
60
     * @return string
61
     */
62
    public function getHttpMethod(): string
63
    {
64
        return 'PUT';
65
    }
66
67
    /**
68
     * Return base URI, e.g. /invoices; /invoice/1/edit and so on.
69
     *
70
     * @see iDoklad::call()
71
     *
72
     * @return string
73
     */
74
    public function getUri(): string
75
    {
76
        $uri = sprintf('IssuedInvoices/%s/FullyPay', $this->id);
77
78
        if (count($this->urlParts) > 0) {
79
            $uri .= '?'.http_build_query($this->urlParts);
80
        }
81
82
        return $uri;
83
    }
84
85
    /**
86
     * Vrátí seznam parametrů, které se předají GuzzleHttp\Client.
87
     *
88
     * @see \GuzzleHttp\Client::request()
89
     * @see iDoklad::call()
90
     *
91
     * @return array
92
     */
93
    public function getGuzzleOptions(): array
94
    {
95
        return [];
96
    }
97
}
98