Completed
Push — master ( d6d8a1...fab734 )
by Elf
04:41
created

AgentServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 54
ccs 0
cts 24
cp 0
rs 10
wmc 5
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 4 1
A register() 0 6 1
A registerAgent() 0 10 2
A registerClient() 0 8 1
1
<?php
2
3
namespace ElfSundae\Laravel\Support\Services\Agent;
4
5
use Jenssegers\Agent\Agent;
6
use Illuminate\Support\ServiceProvider;
7
8
class AgentServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap the service provider.
12
     *
13
     * @return void
14
     */
15
    public function boot()
16
    {
17
        $this->app['view']->share('client', $this->app['client']);
18
    }
19
20
    /**
21
     * Register the service provider.
22
     *
23
     * @return void
24
     */
25
    public function register()
26
    {
27
        $this->registerAgent();
28
29
        $this->registerClient();
30
    }
31
32
    /**
33
     * Register the Agent.
34
     *
35
     * @return void
36
     */
37
    protected function registerAgent()
38
    {
39
        if (! $this->app->bound('agent')) {
40
            $this->app->singleton('agent', function () {
41
                return new Agent;
42
            });
43
44
            $this->app->alias('agent', Agent::class);
45
        }
46
    }
47
48
    /**
49
     * Register the Client.
50
     *
51
     * @return void
52
     */
53
    protected function registerClient()
54
    {
55
        $this->app->singleton('client', function ($app) {
56
            return (new Client)->setAgent($app->make('agent'));
57
        });
58
59
        $this->app->alias('client', Client::class);
60
    }
61
}
62