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

DispatchingClient   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
c 2
b 0
f 0
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 9 2
A __construct() 0 5 1
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