SnowflakeServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 24
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 2
A provides() 0 3 1
A register() 0 7 1
1
<?php
2
/**
3
 * 雪花算法 Provider
4
 *
5
 * @author herry@<[email protected]>
6
 * @version 1.0
7
 * @copyright © 2020 MuCTS.com All Rights Reserved.
8
 */
9
10
namespace MuCTS\Laravel\Snowflake\Providers;
11
12
use Illuminate\Contracts\Support\DeferrableProvider;
13
use Illuminate\Support\ServiceProvider;
14
use MuCTS\Laravel\Snowflake\Snowflake;
15
16
/**
17
 * Class SnowflakeServiceProvider
18
 * @package MuCTS\Laravel\Snowflake\Providers
19
 */
20
class SnowflakeServiceProvider extends ServiceProvider implements DeferrableProvider
21
{
22
    public function register()
23
    {
24
        $this->mergeConfigFrom(
25
            dirname(__DIR__) . '/../config/snowflake.php', 'snowflake'
26
        );
27
        $this->app->singleton('snowflake', function ($app) {
28
            return new Snowflake($app->config['snowflake']);
29
        });
30
    }
31
32
    public function boot()
33
    {
34
        if (!file_exists(config_path('snowflake.php'))) {
35
            $this->publishes([
36
                dirname(__DIR__) . '/../config/snowflake.php' => config_path('snowflake.php'),
37
            ], 'config');
38
        }
39
    }
40
41
    public function provides()
42
    {
43
        return ['snowflake'];
44
    }
45
}