Completed
Push — master ( 41b820...f89445 )
by MeWebStudio - Muharrem
38:39 queued 29:44
created

PurifierServiceProvider::boot()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.3332

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 8
ccs 4
cts 6
cp 0.6667
crap 3.3332
rs 10
c 0
b 0
f 0
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 42
    public function boot()
23
    {
24 42
        if ($this->app instanceof LaravelApplication) {
25 42
            $this->publishes([$this->getConfigSource() => config_path('purifier.php')]);
26
        } 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...
27
            $this->app->configure('purifier');
28
        }
29 42
    }
30
31
    /**
32
     * Get the config source.
33
     * 
34
     * @return string
35
     */
36 42
    protected function getConfigSource()
37
    {
38 42
        return realpath(__DIR__.'/../config/purifier.php');
39
    }
40
41
    /**
42
     * Register the service provider.
43
     *
44
     * @return void
45
     */
46 42
    public function register()
47
    {
48 42
        $this->mergeConfigFrom($this->getConfigSource(), 'purifier');
49
        
50 42
        $this->app->singleton('purifier', function (Container $app) {
51 24
            return new Purifier($app['files'], $app['config']);
52 42
        });
53
54 42
        $this->app->alias('purifier', Purifier::class);
55 42
    }
56
57
    /**
58
     * Get the services provided by the provider.
59
     *
60
     * @return array
61
     */
62 9
    public function provides()
63
    {
64 9
        return ['purifier'];
65
    }
66
}
67