GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Client   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
dl 0
loc 77
ccs 26
cts 28
cp 0.9286
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 5

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getContainer() 0 4 1
A getFromContainer() 0 4 1
A handle() 0 4 1
A hydrate() 0 16 3
A extract() 0 13 1
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Foundation;
4
5
use ApiClients\Foundation\Hydrator\CommandBus\Command\ExtractFQCNCommand;
6
use ApiClients\Foundation\Hydrator\CommandBus\Command\HydrateFQCNCommand;
7
use ApiClients\Foundation\Resource\ResourceInterface;
8
use ApiClients\Tools\CommandBus\CommandBusInterface;
9
use InvalidArgumentException;
10
use Psr\Container\ContainerInterface;
11
use React\Promise\CancellablePromiseInterface;
12
use function React\Promise\resolve;
13
14
final class Client implements ClientInterface
15
{
16
    /**
17
     * @var ContainerInterface
18
     */
19
    private $container;
20
21
    /**
22
     * @var CommandBusInterface
23
     */
24
    private $commandBus;
25
26
    /**
27
     * @param ContainerInterface $container
28
     */
29 7
    public function __construct(ContainerInterface $container)
30
    {
31 7
        $this->container = $container;
32 7
        $this->commandBus = $this->container->get(CommandBusInterface::class);
33 6
    }
34
35
    /**
36
     * @return ContainerInterface
37
     */
38 4
    public function getContainer(): ContainerInterface
39
    {
40 4
        return $this->container;
41
    }
42
43
    /**
44
     * @return mixed
45
     */
46 1
    public function getFromContainer(string $id)
47
    {
48 1
        return $this->container->get($id);
49
    }
50
51
    /**
52
     * @param $command
53
     * @return CancellablePromiseInterface
54
     */
55 4
    public function handle($command): CancellablePromiseInterface
56
    {
57 4
        return $this->commandBus->handle($command);
58
    }
59
60 1
    public function hydrate(string $resource): CancellablePromiseInterface
61
    {
62 1
        $resource = json_decode($resource, true);
63 1
        if (!isset($resource['class'], $resource['properties'])) {
64
            throw new InvalidArgumentException();
65
        }
66
67 1
        if (!class_exists($resource['class'])) {
68
            throw new InvalidArgumentException();
69
        }
70
71 1
        $class = $resource['class'];
72 1
        $json = $resource['properties'];
73
74 1
        return $this->handle(new HydrateFQCNCommand($class, $json));
75
    }
76
77 1
    public function extract(ResourceInterface $resource): CancellablePromiseInterface
78
    {
79 1
        $class = get_class($resource);
80
81 1
        return $this->handle(
82 1
            new ExtractFQCNCommand($class, $resource)
83 1
        )->then(function ($json) use ($class) {
84 1
            return resolve(json_encode([
85 1
                'class' => $class,
86 1
                'properties' => $json,
87
            ]));
88 1
        });
89
    }
90
}
91