GitLabServiceProvider   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Test Coverage

Coverage 95.83%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 34
c 1
b 0
f 0
dl 0
loc 119
ccs 46
cts 48
cp 0.9583
rs 10
wmc 12

8 Methods

Rating   Name   Duplication   Size   Complexity  
A provides() 0 7 1
A register() 0 6 1
A registerAuthFactory() 0 7 1
A setupConfig() 0 11 5
A registerGitlabFactory() 0 10 1
A boot() 0 3 1
A registerManager() 0 10 1
A registerBindings() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Laravel GitLab.
7
 *
8
 * (c) Graham Campbell <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace GrahamCampbell\GitLab;
15
16
use Gitlab\Client;
17
use GrahamCampbell\GitLab\Authenticators\AuthenticatorFactory;
18
use Illuminate\Contracts\Container\Container;
19
use Illuminate\Foundation\Application as LaravelApplication;
20
use Illuminate\Support\ServiceProvider;
21
use Laravel\Lumen\Application as LumenApplication;
22
23
/**
24
 * This is the gitlab service provider class.
25
 *
26
 * @author Graham Campbell <[email protected]>
27
 */
28
class GitLabServiceProvider extends ServiceProvider
29
{
30
    /**
31
     * Boot the service provider.
32
     *
33
     * @return void
34
     */
35 288
    public function boot()
36
    {
37 288
        $this->setupConfig();
38 288
    }
39
40
    /**
41
     * Setup the config.
42
     *
43
     * @return void
44
     */
45 288
    protected function setupConfig()
46
    {
47 288
        $source = realpath($raw = __DIR__.'/../config/gitlab.php') ?: $raw;
48
49 288
        if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) {
50 288
            $this->publishes([$source => config_path('gitlab.php')]);
51
        } elseif ($this->app instanceof LumenApplication) {
52
            $this->app->configure('gitlab');
53
        }
54
55 288
        $this->mergeConfigFrom($source, 'gitlab');
56 288
    }
57
58
    /**
59
     * Register the service provider.
60
     *
61
     * @return void
62
     */
63 288
    public function register()
64
    {
65 288
        $this->registerAuthFactory();
66 288
        $this->registerGitLabFactory();
67 288
        $this->registerManager();
68 288
        $this->registerBindings();
69 288
    }
70
71
    /**
72
     * Register the auth factory class.
73
     *
74
     * @return void
75
     */
76 240
    protected function registerAuthFactory()
77
    {
78 48
        $this->app->singleton('gitlab.authfactory', function () {
79 60
            return new AuthenticatorFactory();
80 288
        });
81
82 288
        $this->app->alias('gitlab.authfactory', AuthenticatorFactory::class);
83 288
    }
84
85
    /**
86
     * Register the gitlab factory class.
87
     *
88
     * @return void
89
     */
90 240
    protected function registerGitlabFactory()
91
    {
92 48
        $this->app->singleton('gitlab.factory', function (Container $app) {
93 48
            $auth = $app['gitlab.authfactory'];
94 48
            $cache = $app['cache'];
95
96 48
            return new GitLabFactory($auth, $cache);
97 288
        });
98
99 288
        $this->app->alias('gitlab.factory', GitLabFactory::class);
100 288
    }
101
102
    /**
103
     * Register the manager class.
104
     *
105
     * @return void
106
     */
107 240
    protected function registerManager()
108
    {
109 48
        $this->app->singleton('gitlab', function (Container $app) {
110 36
            $config = $app['config'];
111 36
            $factory = $app['gitlab.factory'];
112
113 36
            return new GitLabManager($config, $factory);
114 288
        });
115
116 288
        $this->app->alias('gitlab', GitLabManager::class);
117 288
    }
118
119
    /**
120
     * Register the bindings.
121
     *
122
     * @return void
123
     */
124 240
    protected function registerBindings()
125
    {
126 48
        $this->app->bind('gitlab.connection', function (Container $app) {
127 12
            $manager = $app['gitlab'];
128
129 12
            return $manager->connection();
130 288
        });
131
132 288
        $this->app->alias('gitlab.connection', Client::class);
133 288
    }
134
135
    /**
136
     * Get the services provided by the provider.
137
     *
138
     * @return string[]
139
     */
140 24
    public function provides()
141
    {
142
        return [
143 24
            'gitlab.authfactory',
144
            'gitlab.factory',
145
            'gitlab',
146
            'gitlab.connection',
147
        ];
148
    }
149
}
150