ServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 1
A register() 0 9 2
A registerSingletons() 0 10 1
1
<?php
2
3
namespace Suitmedia\Cacheable;
4
5
use Illuminate\Cache\ArrayStore;
6
use Illuminate\Support\ServiceProvider as Provider;
7
8
class ServiceProvider extends Provider
9
{
10
    /**
11
     * Bootstrap the application services.
12
     *
13
     * @return void
14
     */
15
    public function boot(): void
16
    {
17
        $this->publishes([
18
            realpath(dirname(__DIR__).'/config/cacheable.php') => config_path('cacheable.php'),
19
        ], 'config');
20
    }
21
22
    /**
23
     * Register the application services.
24
     *
25
     * @return void
26
     */
27
    public function register(): void
28
    {
29
        $configFile = realpath(dirname(__DIR__).'/config/cacheable.php');
30
        if ($configFile !== false) {
31
            $this->mergeConfigFrom($configFile, 'cacheable');
32
        }
33
34
        $this->registerSingletons();
35
    }
36
37
    /**
38
     * Register the package's singleton objects.
39
     *
40
     * @return void
41
     */
42
    public function registerSingletons(): void
43
    {
44
        $this->app->singleton(CacheableService::class, function () {
45
            return new CacheableService(app('cache'), new ArrayStore());
46
        });
47
48
        $this->app->singleton(CacheableObserver::class, function () {
49
            return new CacheableObserver(collect());
50
        });
51
    }
52
}
53