AsanaServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 32
rs 10
c 1
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A provides() 0 2 1
A register() 0 11 2
A boot() 0 9 2
1
<?php
2
3
namespace Helix\Asana\Api\Laravel;
4
5
use Helix\Asana\Api;
6
use Helix\Asana\Api\Laravel\Command\AsanaCall;
7
use Helix\Asana\Api\Laravel\Command\AsanaGet;
8
use Helix\Asana\Api\Laravel\Command\AsanaTest;
9
use Helix\Asana\Api\SimpleCachePool;
10
use Illuminate\Contracts\Foundation\Application;
11
use Illuminate\Contracts\Support\DeferrableProvider;
12
use Illuminate\Support\Facades\Cache;
13
use Illuminate\Support\Facades\Log;
14
use Illuminate\Support\ServiceProvider;
15
16
class AsanaServiceProvider extends ServiceProvider implements DeferrableProvider {
17
18
    const NAME = 'asana';
19
20
    public function boot () {
21
        $this->publishes([
22
            __DIR__ . '/config/asana.php' => $this->app->configPath('asana.php')
23
        ]);
24
        if ($this->app->runningInConsole()) {
25
            $this->commands([
26
                AsanaTest::class,
27
                AsanaGet::class,
28
                AsanaCall::class,
29
            ]);
30
        }
31
    }
32
33
    public function provides () {
34
        return [self::NAME];
35
    }
36
37
    public function register () {
38
        $this->app->singleton(self::NAME, function(Application $app) {
39
            $config = $app['config'][self::NAME];
40
            $pool = null;
41
            if ($config['cache']) {
42
                $pool = new SimpleCachePool(Cache::store());
43
                $pool->setTtl($config['cache_ttl']);
44
            }
45
            $api = new Api($config['token'], $pool);
46
            $api->setLog(Log::getFacadeRoot());
47
            return $api;
48
        });
49
    }
50
}