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

Counterparty   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 3
eloc 10
c 2
b 0
f 2
dl 0
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A save() 0 4 1
A getCounterpartyAddresses() 0 7 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