ServiceProvider   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 3
dl 0
loc 79
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 4 1
A setupConfig() 0 16 4
A register() 0 12 2
A provides() 0 4 1
A config() 0 4 1
1
<?php
2
3
namespace Freyo\LaravelEntWechat;
4
5
use EntWeChat\Foundation\Application as EntWeChatApplication;
6
use Illuminate\Foundation\Application as LaravelApplication;
7
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
8
use Laravel\Lumen\Application as LumenApplication;
9
10
class ServiceProvider extends LaravelServiceProvider
11
{
12
    /**
13
     * 延迟加载.
14
     *
15
     * @var bool
16
     */
17
    protected $defer = true;
18
19
    /**
20
     * Boot the provider.
21
     *
22
     * @return void
23
     */
24
    public function boot()
25
    {
26
        $this->setupConfig();
27
    }
28
29
    /**
30
     * Setup the config.
31
     *
32
     * @return void
33
     */
34
    protected function setupConfig()
35
    {
36
        $source = realpath(__DIR__.'/config.php');
37
38
        if ($this->app instanceof LaravelApplication) {
0 ignored issues
show
Bug introduced by
The class Illuminate\Foundation\Application does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
39
            if ($this->app->runningInConsole()) {
40
                $this->publishes([
41
                    $source => config_path('entwechat.php'),
42
                ]);
43
            }
44
        } elseif ($this->app instanceof LumenApplication) {
0 ignored issues
show
Bug introduced by
The class Laravel\Lumen\Application does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
45
            $this->app->configure('entwechat');
46
        }
47
48
        $this->mergeConfigFrom($source, 'entwechat');
49
    }
50
51
    /**
52
     * Register the provider.
53
     *
54
     * @return void
55
     */
56
    public function register()
57
    {
58
        $this->app->singleton(EntWeChatApplication::class, function ($laravelApp) {
59
            $app = new EntWeChatApplication(config('entwechat'));
60
            if (config('entwechat.use_laravel_cache')) {
61
                $app->cache = new CacheBridge();
62
            }
63
            $app->server->setRequest($laravelApp['request']);
64
65
            return $app;
66
        });
67
    }
68
69
    /**
70
     * 提供的服务
71
     *
72
     * @return array
73
     */
74
    public function provides()
75
    {
76
        return ['wechat', EntWeChatApplication::class];
77
    }
78
79
    /**
80
     * Get config value by key.
81
     *
82
     * @return \Illuminate\Config\Repository
83
     */
84
    private function config()
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
85
    {
86
        return $this->app['config'];
87
    }
88
}
89