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.
Completed
Push — master ( 9faab8...e694a5 )
by Cees-Jan
06:16
created

src/Factory.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Foundation;
4
5
use ApiClients\Foundation\Hydrator\Factory as HydratorFactory;
6
use ApiClients\Foundation\Hydrator\Hydrator;
7
use ApiClients\Foundation\Transport\ClientInterface;
0 ignored issues
show
This use statement conflicts with another class in this namespace, ApiClients\Foundation\ClientInterface.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
8
use ApiClients\Foundation\Transport\Factory as TransportFactory;
9
use ApiClients\Tools\CommandBus\CommandBusInterface;
10
use ApiClients\Tools\CommandBus\Factory as CommandBusFactory;
11
use DI\ContainerBuilder;
12
use Interop\Container\ContainerInterface;
13
use InvalidArgumentException;
14
use React\EventLoop\LoopInterface;
15
16
final class Factory
17
{
18
    public static function create(
19
        LoopInterface $loop,
20
        array $options = []
21
    ): Client {
22
        return new Client(
23
            self::createContainer($loop, $options)
24
        );
25
    }
26
27
    private static function createContainer(LoopInterface $loop, array $options): ContainerInterface
28
    {
29
        $container = new ContainerBuilder();
30
31
        $container->addDefinitions([
32
            LoopInterface::class => $loop,
33
            ClientInterface::class => function (ContainerInterface $container, LoopInterface $loop) use ($options) {
34
                return self::createTransport($container, $loop, $options);
35
            },
36
            Hydrator::class => function (ContainerInterface $container) use ($options) {
37
                return self::createHydrator($container, $options);
38
            },
39
            CommandBusInterface::class => function (ContainerInterface $container) {
40
                return CommandBusFactory::create($container);
41
            },
42
        ]);
43
        $container->addDefinitions($options[Options::CONTAINER_DEFINITIONS] ?? []);
44
45
        return $container->build();
46
    }
47
48 View Code Duplication
    private static function createTransport(
49
        ContainerInterface $container,
50
        LoopInterface $loop,
51
        array $options = []
52
    ): ClientInterface {
53
        if (!isset($options[Options::TRANSPORT_OPTIONS])) {
54
            throw new InvalidArgumentException('Missing Transport options');
55
        }
56
57
        return TransportFactory::create($container, $loop, $options[Options::TRANSPORT_OPTIONS]);
58
    }
59
60 View Code Duplication
    private static function createHydrator(ContainerInterface $container, array $options = [])
61
    {
62
        if (!isset($options[Options::HYDRATOR_OPTIONS])) {
63
            throw new InvalidArgumentException('Missing Hydrator options');
64
        }
65
66
        return HydratorFactory::create($container, $options[Options::HYDRATOR_OPTIONS]);
67
    }
68
}
69