Test Failed
Push — master ( 02a63f...ddb4ba )
by Oliver
05:18
created

DocumentsServiceProvider::setupRoutes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 12
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace Webfactor\Laravel\Backpack\Documents;
4
5
use Illuminate\Routing\Router;
6
use Illuminate\Support\ServiceProvider;
7
8
class DocumentsServiceProvider extends ServiceProvider
9
{
10
11
    /**
12
     * Where the route file lives, both inside the package and in the app (if overwritten).
13
     *
14
     * @var string
15
     */
16
    public $routeFilePath = '/../routes/webfactor/documents.php';
17
18
    /**
19
     * Perform post-registration booting of services.
20
     *
21
     * @return void
22
     */
23
    public function boot()
24
    {
25
        // define the routes for the application
26
        $this->setupRoutes($this->app->router);
0 ignored issues
show
Bug introduced by
Accessing router on the interface Illuminate\Contracts\Foundation\Application suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
27
28
        $this->loadTranslationsFrom(realpath(__DIR__.'/../resources/lang'), 'webfactor');
29
30
        $this->mergeConfigFrom(
31
            __DIR__.'/../config/webfactor/documents.php', 'webfactor.documents'
32
        );
33
34
        $this->publishFiles();
35
    }
36
37
    /**
38
     * Register any package services.
39
     *
40
     * @return void
41
     */
42
    public function register()
43
    {
44
        //
45
    }
46
47
    public function publishFiles()
48
    {
49
        // publish config file
50
        $this->publishes([__DIR__.'/../config' => config_path()], 'config');
51
52
        // publish lang files
53
        $this->publishes([__DIR__.'/../resources/lang' => resource_path('lang/vendor/webfactor')], 'lang');
54
55
        // publish migrations
56
        $this->publishes([__DIR__.'/../database/migrations' => database_path('migrations')], 'migrations');
57
58
        // publish seeder
59
        $this->publishes([__DIR__.'/../database/seeds' => database_path('seeds')], 'seeder');
60
61
        // publish factory
62
        $this->publishes([__DIR__.'/../database/factories' => database_path('factories')], 'factories');
63
    }
64
65
    /**
66
     * Define the routes for the application.
67
     *
68
     * @param \Illuminate\Routing\Router $router
69
     *
70
     * @return void
71
     */
72
    public function setupRoutes(Router $router)
0 ignored issues
show
Unused Code introduced by
The parameter $router 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...
73
    {
74
        // by default, use the routes file provided in vendor
75
        $routeFilePathInUse = __DIR__.$this->routeFilePath;
76
77
        // but if there's a file with the same name in routes/webfactor, use that one
78
        if (file_exists(base_path().$this->routeFilePath)) {
79
            $routeFilePathInUse = base_path().$this->routeFilePath;
80
        }
81
82
        $this->loadRoutesFrom($routeFilePathInUse);
83
    }
84
}
85