Passed
Push — master ( 23ab98...82cce0 )
by y
01:46
created

AsanaServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

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

3 Methods

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