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

AsanaServiceProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
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
}