Completed
Push — master ( db1e7e...28fc27 )
by Songda
08:23 queued 41s
created

PayServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 6
Bugs 1 Features 0
Metric Value
wmc 6
c 6
b 1
f 0
lcom 1
cbo 2
dl 0
loc 57
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 11 4
A register() 0 11 1
A provides() 0 4 1
1
<?php
2
3
namespace Yansongda\LaravelPay;
4
5
use Illuminate\Foundation\Application as LaravelApplication;
6
use Illuminate\Support\ServiceProvider;
7
use Laravel\Lumen\Application as LumenApplication;
8
use Yansongda\Pay\Pay;
9
10
class PayServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Determin is defer.
14
     *
15
     * @var bool
16
     */
17
    protected $defer = true;
18
19
    /**
20
     * Boot the service.
21
     *
22
     * @author yansongda <[email protected]>
23
     */
24
    public function boot()
25
    {
26
        if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) {
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...
27
            $this->publishes([
28
                dirname(__DIR__).'/config/pay.php' => config_path('pay.php')],
29
                'laravel-pay'
30
            );
31
        } 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...
32
            $this->app->configure('pay');
33
        }
34
    }
35
36
    /**
37
     * Regist the service.
38
     *
39
     * @author yansongda <[email protected]>
40
     *
41
     * @return void
42
     */
43
    public function register()
44
    {
45
        $this->mergeConfigFrom(dirname(__DIR__).'/config/pay.php', 'pay');
46
47
        $this->app->singleton('pay.alipay', function () {
48
            return Pay::alipay(config('pay.alipay'));
49
        });
50
        $this->app->singleton('pay.wechat', function () {
51
            return Pay::wechat(config('pay.wechat'));
52
        });
53
    }
54
55
    /**
56
     * Get services.
57
     *
58
     * @author yansongda <[email protected]>
59
     *
60
     * @return array
61
     */
62
    public function provides()
63
    {
64
        return ['pay.alipay', 'pay.wechat'];
65
    }
66
}
67