Completed
Pull Request — master (#45)
by Pierre
03:10 queued 16s
created

PurifierServiceProvider::setupConfig()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.1755

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 10
ccs 7
cts 9
cp 0.7778
crap 4.1755
rs 9.2
1
<?php namespace Mews\Purifier;
2
3
use Illuminate\Container\Container;
4
use Illuminate\Foundation\Application as LaravelApplication;
5
use Illuminate\Support\ServiceProvider;
6
use Laravel\Lumen\Application as LumenApplication;
7
8
class PurifierServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Indicates if loading of the provider is deferred.
12
     *
13
     * @var bool
14
     */
15
    protected $defer = true;
16
17
    /**
18
     * Boot the service provider.
19
     *
20
     * @return null
21
     */
22 18
    public function boot()
23
    {
24 18
        $this->setupConfig();
25 18
    }
26
27
    /**
28
     * Setup the config.
29
     *
30
     * @return void
31
     */
32 18
    protected function setupConfig()
33
    {
34 18
        $source = realpath(__DIR__.'/../config/purifier.php');
35 18
        if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) {
36 18
            $this->publishes([$source => config_path('purifier.php')]);
37 18
        } 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...
38
            $this->app->configure('purifier');
39
        }
40 18
        $this->mergeConfigFrom($source, 'purifier');
41 18
    }
42
43
44
    /**
45
     * Register the service provider.
46
     *
47
     * @return void
48
     */
49
    public function register()
50
    {
51 18
        $this->app->singleton('purifier', function (Container $app) {
52 18
            return new Purifier($app['files'], $app['config']);
53 18
        });
54
55 18
        $this->app->alias('purifier', Purifier::class);
56 18
    }
57
58
    /**
59
     * Get the services provided by the provider.
60
     *
61
     * @return array
62
     */
63 27
    public function provides()
64
    {
65 27
        return ['purifier'];
66
    }
67
}
68