Passed
Push — master ( de53d8...b05c35 )
by Jhao
02:13
created

DispatchingClient::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 2
b 0
f 0
nc 1
nop 4
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
/**
4
 * This file is part of RussianPost SDK package.
5
 *
6
 * © Appwilio (http://appwilio.com), JhaoDa (https://github.com/jhaoda)
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Appwilio\RussianPostSDK\Dispatching;
15
16
use Psr\Log\NullLogger;
17
use Psr\Log\LoggerAwareTrait;
18
use Psr\Log\LoggerAwareInterface;
19
use GuzzleHttp\ClientInterface;
20
use Appwilio\RussianPostSDK\Dispatching\Http\ApiClient;
21
use Appwilio\RussianPostSDK\Dispatching\Http\Authentication;
22
use Appwilio\RussianPostSDK\Dispatching\Exceptions\UnknownEndpoint;
23
use Appwilio\RussianPostSDK\Dispatching\Endpoints\Orders\Orders;
24
use Appwilio\RussianPostSDK\Dispatching\Endpoints\Services\Services;
25
use Appwilio\RussianPostSDK\Dispatching\Endpoints\Settings\Settings;
26
use Appwilio\RussianPostSDK\Dispatching\Endpoints\Documents\Documents;
27
28
/**
29
 * Class DispatchingClient
30
 *
31
 * @property-read  Orders     $orders
32
 * @property-read  Documents  $documents
33
 * @property-read  Services   $services
34
 * @property-read  Settings   $settings
35
 *
36
 * @package Appwilio\RussianPostSDK\Dispatching
37
 */
38
final class DispatchingClient implements LoggerAwareInterface
39
{
40
    use LoggerAwareTrait;
41
42
    private const ENDPOINTS = [
43
        'orders'    => Orders::class,
44
        'services'  => Services::class,
45
        'settings'  => Settings::class,
46
        'documents' => Documents::class,
47
    ];
48
49
    /** @var ApiClient */
50
    private $client;
51
52 3
    public function __construct(string $login, string $password, string $token, ClientInterface $httpClient)
53
    {
54 3
        $this->logger = new NullLogger();
55
56 3
        $this->client = new ApiClient(new Authentication($login, $password, $token), $httpClient);
57 3
    }
58
59 2
    public function __get(string $property)
60
    {
61 2
        if (isset(self::ENDPOINTS[$property])) {
62 1
            $class = self::ENDPOINTS[$property];
63
64 1
            return new $class($this->client);
65
        }
66
67 1
        throw new UnknownEndpoint($property);
68
    }
69
}
70