Passed
Push — master ( 39d0f8...ef103c )
by Daniel
02:09
created

GitlabServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 18
ccs 0
cts 13
cp 0
crap 2
rs 9.9
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace DanielPieper\MergeReminder\ServiceProvider;
4
5
use Gitlab\Client;
6
use Gitlab\HttpClient\Builder;
7
use Http\Client\Common\Plugin\CachePlugin;
8
use Http\Client\Common\Plugin\LoggerPlugin;
9
use Http\Client\HttpClient;
10
use Http\Discovery\StreamFactoryDiscovery;
11
use League\Container\Container;
12
use League\Container\ServiceProvider\AbstractServiceProvider;
13
use Psr\Cache\CacheItemPoolInterface;
14
use Psr\Log\LoggerInterface;
15
16
class GitlabServiceProvider extends AbstractServiceProvider
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    protected $provides = [
22
        LoggerPlugin::class,
23
        CachePlugin::class,
24
        Builder::class,
25
        Client::class,
26
    ];
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function register()
32
    {
33
        /** @var Container $container */
34
        $container = $this->getContainer();
35
36
        $container->share(LoggerPlugin::class)
37
            ->addArgument(LoggerInterface::class);
38
39
        $container->share(CachePlugin::class)
40
            ->addArguments([
41
                CacheItemPoolInterface::class,
42
                StreamFactoryDiscovery::find(),
43
                [
44
                    'default_ttl' => 600,
45
                    'respect_response_cache_directives' => [],
46
                ]
47
            ]);
48
49
        $container->share(Builder::class)
50
            ->addArgument(HttpClient::class)
51
            ->addMethodCall('addPlugin', [LoggerPlugin::class])
52
            ->addMethodCall('addPlugin', [CachePlugin::class]);
53
54
        $container->share(Client::class)
55
            ->addArgument(Builder::class)
56
            ->addMethodCall('setUrl', ['GITLAB_URL'])
57
            ->addMethodCall('authenticate', [
58
                'GITLAB_TOKEN',
59
                Client::AUTH_URL_TOKEN,
60
            ]);
61
    }
62
}
63