CreateContact   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 73
loc 73
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A getModelClass() 4 4 1
A getHttpMethod() 4 4 1
A getUri() 4 4 1
A getGuzzleOptions() 8 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
3
namespace Fousky\Component\iDoklad\Functions\Contacts;
4
5
use Fousky\Component\iDoklad\Functions\iDokladAbstractFunction;
6
use Fousky\Component\iDoklad\Model\Contacts\ContactApiModel;
7
use Fousky\Component\iDoklad\Model\Contacts\ContactPostApiModel;
8
9
/**
10
 * @see https://app.idoklad.cz/developer/Help/v2/cs/Api?apiId=POST-api-v2-Contacts
11
 *
12
 * @author Lukáš Brzák <[email protected]>
13
 */
14 View Code Duplication
class CreateContact 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...
15
{
16
    /** @var ContactPostApiModel $data */
17
    protected $data;
18
19
    /**
20
     * @param ContactPostApiModel $data
21
     *
22
     * @throws \Fousky\Component\iDoklad\Exception\InvalidModelException
23
     */
24
    public function __construct(ContactPostApiModel $data)
25
    {
26
        $this->data = $data;
27
28
        $this->validate($data);
29
    }
30
31
    /**
32
     * Get iDokladModelInterface class.
33
     *
34
     * @see iDokladModelInterface
35
     *
36
     * @return string
37
     */
38
    public function getModelClass(): string
39
    {
40
        return ContactApiModel::class;
41
    }
42
43
    /**
44
     * GET|POST|PUT|DELETE e.g.
45
     *
46
     * @see iDoklad::request()
47
     *
48
     * @return string
49
     */
50
    public function getHttpMethod(): string
51
    {
52
        return 'POST';
53
    }
54
55
    /**
56
     * Return base URI, e.g. /invoices; /invoice/1/edit and so on.
57
     *
58
     * @see iDoklad::call()
59
     *
60
     * @return string
61
     */
62
    public function getUri(): string
63
    {
64
        return 'Contacts';
65
    }
66
67
    /**
68
     * Vrátí seznam parametrů, které se předají GuzzleHttp\Client.
69
     *
70
     * @see \GuzzleHttp\Client::request()
71
     * @see iDoklad::call()
72
     *
73
     * @throws \ReflectionException
74
     * @throws \InvalidArgumentException
75
     *
76
     * @return array
77
     */
78
    public function getGuzzleOptions(): array
79
    {
80
        return [
81
            'json' => $this->data->toArray([
82
                ContactApiModel::TOARRAY_REMOVE_NULLS => true,
83
            ]),
84
        ];
85
    }
86
}
87