Passed
Push — master ( 69d4f6...006bbe )
by Jhao
02:34
created

DispatchingClient   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
c 2
b 0
f 0
dl 0
loc 36
ccs 8
cts 10
cp 0.8
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setLogger() 0 3 1
A __get() 0 9 2
A __construct() 0 3 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\LoggerInterface;
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
use Appwilio\RussianPostSDK\Dispatching\Endpoints\PostOffices\PostOffices;
0 ignored issues
show
Bug introduced by
The type Appwilio\RussianPostSDK\...PostOffices\PostOffices was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
29
/**
30
 * Class DispatchingClient.
31
 *
32
 * @property-read  Orders     $orders
33
 * @property-read  Documents  $documents
34
 * @property-read  Services   $services
35
 * @property-read  Settings   $settings
36
 */
37
final class DispatchingClient implements LoggerAwareInterface
38
{
39
    private const ENDPOINTS = [
40
        'orders'    => Orders::class,
41
        'services'  => Services::class,
42
        'settings'  => Settings::class,
43
        'documents' => Documents::class,
44
    ];
45
46
    /** @var ApiClient */
47
    private $client;
48
49 3
    public function __construct(string $login, string $password, string $token, ClientInterface $httpClient)
50
    {
51 3
        $this->client = new ApiClient(new Authentication($login, $password, $token), $httpClient, new NullLogger());
52 3
    }
53
54 2
    public function __get(string $property)
55
    {
56 2
        if (isset(self::ENDPOINTS[$property])) {
57 1
            $class = self::ENDPOINTS[$property];
58
59 1
            return new $class($this->client);
60
        }
61
62 1
        throw new UnknownEndpoint($property);
63
    }
64
65
    /**
66
     * Sets a logger.
67
     *
68
     * @param LoggerInterface $logger
69
     */
70
    public function setLogger(LoggerInterface $logger)
71
    {
72
        $this->client->setLogger($logger);
73
    }
74
}
75