GravatarServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
ccs 4
cts 4
cp 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arcanedev\Gravatar;
6
7
use Arcanedev\Gravatar\Contracts\Gravatar as GravatarContract;
8
use Arcanedev\Support\Providers\PackageServiceProvider;
9
use Illuminate\Contracts\Support\DeferrableProvider;
10
11
/**
12
 * Class     GravatarServiceProvider
13
 *
14
 * @author   ARCANEDEV <[email protected]>
15
 */
16
class GravatarServiceProvider extends PackageServiceProvider implements DeferrableProvider
17
{
18
    /* -----------------------------------------------------------------
19
     |  Properties
20
     | -----------------------------------------------------------------
21
     */
22
23
    /**
24
     * Package name.
25
     *
26
     * @var string
27
     */
28
    protected $package = 'gravatar';
29
30
    /* -----------------------------------------------------------------
31
     |  Main Methods
32
     | -----------------------------------------------------------------
33
     */
34
35
    /**
36
     * Register the service provider.
37
     */
38 100
    public function register(): void
39
    {
40 100
        parent::register();
41
42 100
        $this->registerConfig();
43
44 50
        $this->singleton(GravatarContract::class, function($app) {
45
            /** @var  \Illuminate\Contracts\Config\Repository  $config */
46 76
            $config = $app['config'];
47
48 76
            return new Gravatar(
49 76
                $config->get('gravatar.default', 'identicon'),
50 76
                $config->get('gravatar.size', 80),
51 76
                $config->get('gravatar.max-rating', 'g')
52
            );
53 100
        });
54 100
    }
55
56
    /**
57
     * Boot the service provider.
58
     */
59 100
    public function boot(): void
60
    {
61 100
        if ($this->app->runningInConsole()) {
62 100
            $this->publishConfig();
63
        }
64 100
    }
65
66
    /**
67
     * Get the services provided by the provider.
68
     *
69
     * @return array
70
     */
71 4
    public function provides(): array
72
    {
73
        return [
74 4
            GravatarContract::class,
75
        ];
76
    }
77
}
78