Passed
Pull Request — master (#8)
by Sergey
02:18
created

Counterparty::save()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 9
c 1
b 0
f 1
dl 0
loc 12
rs 9.9666
cc 1
nc 1
nop 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SergeyNezbritskiy\NovaPoshta\Models;
6
7
use SergeyNezbritskiy\NovaPoshta\Connection;
8
use SergeyNezbritskiy\NovaPoshta\ModelInterface;
9
use SergeyNezbritskiy\NovaPoshta\NovaPoshtaApiException;
10
11
class Counterparty implements ModelInterface
12
{
13
    private const MODEL_NAME = 'Counterparty';
14
15
    private Connection $connection;
16
17
    /**
18
     * @param Connection $connection
19
     */
20
    public function __construct(Connection $connection)
21
    {
22
        $this->connection = $connection;
23
    }
24
25
    /**
26
     * @param string $firstName
27
     * @param string $middleName
28
     * @param string $lastName
29
     * @param string $phone
30
     * @param string $email
31
     * @param string $type
32
     * @param string $property
33
     * @return array
34
     * @throws NovaPoshtaApiException
35
     * phpcs:disable Generic.Files.LineLength.TooLong
36
     */
37
    public function save(string $firstName, string $middleName, string $lastName, string $phone, string $email, string $type, string $property): array
38
    {
39
        $params = [
40
            'FirstName' => $firstName,
41
            'MiddleName' => $middleName,
42
            'LastName' => $lastName,
43
            'Phone' => $phone,
44
            'Email' => $email,
45
            'CounterpartyType' => $type,
46
            'CounterpartyProperty' => $property,
47
        ];
48
        return $this->connection->post(self::MODEL_NAME, 'save', $params);
49
    }
50
51
    /**
52
     * @param string $counterpartyRef
53
     * @param string $counterpartyProperty
54
     * @return array
55
     * @throws NovaPoshtaApiException
56
     */
57
    public function getCounterpartyAddresses(string $counterpartyRef, string $counterpartyProperty): array
58
    {
59
        $params = [
60
            'Ref' => $counterpartyRef,
61
            'CounterpartyProperty' => $counterpartyProperty,
62
        ];
63
        return $this->connection->post(self::MODEL_NAME, 'getCounterpartyAddresses', $params);
64
    }
65
}
66