Passed
Push — master ( 84fad3...cf1b89 )
by Sergey
01:02 queued 12s
created

Counterparty::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
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 array $counterparty Array containing the necessary params.
27
     *    $counterparty = [
28
     *      'FirstName'             => (string) First name. Required.
29
     *      'MiddleName'            => (string) Middle name. Required.
30
     *      'LastName'              => (string) Last name. Required.
31
     *      'Phone'                 => (string) Phone number. Required.
32
     *      'Email'                 => (string) Email. Required.
33
     *      'CounterpartyType'      => (string) Counterparty type. Required.
34
     *      'CounterpartyProperty'  => (string) Counterparty property. Required.
35
     *    ]
36
     * @return array
37
     * @throws NovaPoshtaApiException
38
     */
39
    public function save(array $counterparty): array
40
    {
41
        $result = $this->connection->post(self::MODEL_NAME, 'save', $counterparty);
42
        return array_shift($result);
43
    }
44
45
    /**
46
     * @param string $counterpartyRef
47
     * @param string $counterpartyProperty
48
     * @return array
49
     * @throws NovaPoshtaApiException
50
     */
51
    public function getCounterpartyAddresses(string $counterpartyRef, string $counterpartyProperty): array
52
    {
53
        $params = [
54
            'Ref' => $counterpartyRef,
55
            'CounterpartyProperty' => $counterpartyProperty,
56
        ];
57
        return $this->connection->post(self::MODEL_NAME, 'getCounterpartyAddresses', $params);
58
    }
59
}
60