CrayServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 41
rs 9.264
c 0
b 0
f 0
1
<?php
2
3
namespace JunaidQadirB\Cray;
4
5
use Illuminate\Database\Migrations\MigrationCreator;
6
use Illuminate\Support\ServiceProvider;
7
use JunaidQadirB\Cray\Console\Commands\ControllerMakeCommand;
8
use JunaidQadirB\Cray\Console\Commands\FactoryMakeCommand;
9
use JunaidQadirB\Cray\Console\Commands\Cray;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, JunaidQadirB\Cray\Cray.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
10
use JunaidQadirB\Cray\Console\Commands\MigrateMakeCommand;
11
use JunaidQadirB\Cray\Console\Commands\ModelMakeCommand;
12
use JunaidQadirB\Cray\Console\Commands\RequestMakeCommand;
13
use JunaidQadirB\Cray\Console\Commands\ViewMakeCommand;
14
15
class CrayServiceProvider extends ServiceProvider
16
{
17
18
    protected $commands = [
19
        ControllerMakeCommand::class,
20
        FactoryMakeCommand::class,
21
        Cray::class,
22
        MigrateMakeCommand::class,
23
        ModelMakeCommand::class,
24
        RequestMakeCommand::class,
25
        ViewMakeCommand::class,
26
    ];
27
28
    /**
29
     * Bootstrap the application services.
30
     */
31
    public function boot()
32
    {
33
34
        /*
35
         * Optional methods to load your package assets
36
         */
37
        // $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'cray');
38
        // $this->loadViewsFrom(__DIR__.'/../resources/views', 'cray');
39
        // $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
40
        // $this->loadRoutesFrom(__DIR__.'/routes.php');
41
42
//        if ($this->app->runningInConsole()) {
43
            $this->publishes([
44
                __DIR__ . '/../config/config.php' => config_path('cray.php'),
45
            ], 'cray');
46
47
            // Publishing the views.
48
            /*$this->publishes([
49
                __DIR__.'/../resources/views' => resource_path('views/vendor/cray'),
50
            ], 'views');*/
51
52
            // Publishing assets.
53
            $this->publishes([
54
                __DIR__ . '/../resources/stubs' => resource_path('stubs')
55
            ], 'cray');
56
57
            // Publishing the translation files.
58
            /*$this->publishes([
59
                __DIR__.'/../resources/lang' => resource_path('lang/vendor/cray'),
60
            ], 'lang');*/
61
62
        $this->app->when(MigrationCreator::class)
63
            ->needs('$customStubPath')
64
            ->give(function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
65
                return resource_path('stubs');
66
            });
67
68
            // Registering package commands.
69
            $this->commands($this->commands);
70
//        }
71
    }
72
73
    /**
74
     * Register the application services.
75
     */
76
    public function register()
77
    {
78
        // Automatically apply the package configuration
79
        $this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'cray');
80
81
        // Register the main class to use with the facade
82
        $this->app->singleton('cray', function () {
83
            return new Cray;
0 ignored issues
show
Bug introduced by
The call to Cray::__construct() misses a required argument $files.

This check looks for function calls that miss required arguments.

Loading history...
84
        });
85
    }
86
}
87