Completed
Push — master ( 86a38a...27ba4c )
by Elf
03:00
created

AgentServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 5
c 4
b 0
f 0
lcom 1
cbo 3
dl 0
loc 58
ccs 0
cts 26
cp 0
rs 10

4 Methods

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