People::validateDocument()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace JulianoBailao\DomusApi\Endpoints;
4
5
use JulianoBailao\DomusApi\Contracts\CreationContract;
6
use JulianoBailao\DomusApi\Contracts\GetContract;
7
use JulianoBailao\DomusApi\Core\Endpoint;
8
use JulianoBailao\DomusApi\Data\PersonData;
9
10
class People extends Endpoint implements GetContract, CreationContract
11
{
12
    /**
13
     * Get a page of people list.
14
     *
15
     * @param array $query the request query string.
16
     *
17
     * @return stdClass
18
     */
19 3
    public function paginate(array $query = [])
20
    {
21 3
        return $this->page('operacional/pessoas', $query);
22
    }
23
24
    /**
25
     * Get a specific person.
26
     *
27
     * @param int $id the person id.
28
     *
29
     * @return stdClass
30
     */
31 3
    public function get($id)
32
    {
33 3
        return $this->run('GET', 'pedidovenda-rest/pessoas/'.$id);
34
    }
35
36
    /**
37
     * Check if the document already exists.
38
     *
39
     * @param string $documentNumber
40
     *
41
     * @return stdClass
42
     */
43 3
    public function document($documentNumber)
44
    {
45 3
        return $this->run('GET', 'pedidovenda-rest/pessoas/documento', ['query' => ['num' => $documentNumber]]);
46
    }
47
48
    /**
49
     * Validate the document.
50
     *
51
     * @param string $documentNumber
52
     *
53
     * @return stdClass
54
     */
55 3
    public function validateDocument($documentNumber)
56
    {
57 3
        return $this->run('GET', 'pedidovenda-rest/pessoas/validarDocumento', ['query' => ['num' => $documentNumber]]);
58
    }
59
60
    /**
61
     * Get the delivery address from a person.
62
     *
63
     * @param int $id
64
     *
65
     * @return stdClass
66
     */
67 3
    public function deliveryAddresses($id)
68
    {
69 3
        return $this->run('GET', 'pedidovenda-rest/pessoas/'.$id.'/enderecosentrega');
70
    }
71
72
    /**
73
     * Get the default values from a person.
74
     *
75
     * @param int $id
76
     *
77
     * @return stdClass
78
     */
79 3
    public function defaultValues($id)
80
    {
81 3
        return $this->run('GET', 'pedidovenda-rest/pessoas/'.$id.'/valoresPadraoPedido');
82
    }
83
84
    /**
85
     * Create a new person.
86
     *
87
     * @return PersonData
88
     */
89 3
    public function create()
90
    {
91 3
        return new PersonData($this);
92
    }
93
94
    /**
95
     * Update a existing person.
96
     *
97
     * @param int $id
98
     *
99
     * @return stdClass
100
     */
101 3
    public function update($id)
102
    {
103 3
        return new PersonData($this, $id);
104
    }
105
106
    /**
107
     * Send the save request.
108
     *
109
     * @param PersonData $data
110
     *
111
     * @return stdClass
112
     */
113 6 View Code Duplication
    public function save(PersonData $data)
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...
114
    {
115 6
        $id = $data->getId();
116
117 6
        return $this->run(
118 6
            $id == null ? 'POST' : 'PUT',
119 6
            'pedidovenda-rest/pessoas'.($id > 0 ? '/'.$id : null),
120 6
            ['json' => $data->toArray()]
121 6
        );
122
    }
123
}
124