ServiceProvider::publishAssets()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 12
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace TypeHints\Unused;
4
5
use Illuminate\Filesystem\Filesystem;
6
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
7
8
class ServiceProvider extends BaseServiceProvider
9
{
10
    public function register()
11
    {
12
        $configPath = __DIR__.'/../config/laravelunused.php';
13
14
        $this->mergeConfigFrom($configPath, 'laravelunused');
15
    }
16
17
    public function boot()
18
    {
19
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'laravelunused');
20
21
        $this->publishRoutes();
22
23
        $this->publishAssets();
24
25
        $this->publishConfig();
26
    }
27
28
    public function publishRoutes()
29
    {
30
        $routeConfig = [
31
            'namespace'  => 'TypeHints\Unused\Controllers',
32
            'prefix'     => $this->app['config']->get('laravelunused.route_prefix'),
33
            'middleware' => $this->app['config']->get('laravelunused.middleware'),
34
        ];
35
36
        $this->app['router']->group($routeConfig, function ($router) {
37
            $router->get('/{view?}', [
38
                'uses' => 'LaravelUnusedController',
39
                'as'   => 'laravelunused.dashboard',
40
            ])->where('view', '(.*)');
41
42
            $router->delete('/delete/{view}', [
43
                'uses' => 'LaravelUnusedController@delete',
0 ignored issues
show
Bug introduced by
The controller App\Http\Controllers\LaravelUnusedController does not seem to exist.

If there is a route defined but the controller class cannot be found there are two options: 1. the controller class needs to be implemented or 2. the route is outdated and can be removed.

If ?FooController? was found and ?BarController? is missing for the following example, either the controller should be implemented or the route should be removed:

$app->group(['as' => 'foo', 'prefix' => 'foo', 'namespace' => 'Foo'], function($app) {
    $app->group(['as' => 'foo', 'prefix' => 'foo'], function($app) {
        $app->get('/all/{from}/{to}', ['as' => 'all', 'uses' => 'FooController@getFoo']);
        $app->get('/all/{from}/{to}', ['as' => 'all', 'uses' => 'BarController@getBar']);
    });
});
Loading history...
44
                'as'   => 'laravelunused.delete',
45
            ]);
46
        });
47
    }
48
49
    /**
50
     * @return void
51
     */
52
    protected function publishAssets(): void
53
    {
54
        // if (file_exists(public_path('vendor/laravelunused'))) {
55
        //     return;
56
        // }
57
58
        // (new Filesystem)->link(
59
        //     __DIR__.'/../public',
60
        //     public_path('vendor/laravelunused')
61
        // );
62
63
        $this->publishes([__DIR__.'/../public' => public_path('vendor/laravelunused')], 'laravelunused-assets');
0 ignored issues
show
Bug introduced by
The function public_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
        $this->publishes([__DIR__.'/../public' => /** @scrutinizer ignore-call */ public_path('vendor/laravelunused')], 'laravelunused-assets');
Loading history...
64
    }
65
66
    /**
67
     * @return void
68
     */
69
    protected function publishConfig(): void
70
    {
71
        $this->publishes([__DIR__.'/../config/laravelunused.php' => config_path('laravelunused.php')], 'config');
0 ignored issues
show
Bug introduced by
The function config_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
        $this->publishes([__DIR__.'/../config/laravelunused.php' => /** @scrutinizer ignore-call */ config_path('laravelunused.php')], 'config');
Loading history...
72
    }
73
}
74