DocumentsServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 75
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 9 1
A register() 0 6 1
A publishFiles() 0 17 1
A setupRoutes() 0 12 2
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->publishFiles();
31
    }
32
33
    /**
34
     * Register any package services.
35
     *
36
     * @return void
37
     */
38
    public function register()
39
    {
40
        $this->mergeConfigFrom(
41
            __DIR__.'/../config/webfactor/documents.php', 'webfactor.documents'
42
        );
43
    }
44
45
    public function publishFiles()
46
    {
47
        // publish config file
48
        $this->publishes([__DIR__.'/../config' => config_path()], 'config');
49
50
        // publish lang files
51
        $this->publishes([__DIR__.'/../resources/lang' => resource_path('lang/vendor/webfactor')], 'lang');
52
53
        // publish migrations
54
        $this->publishes([__DIR__.'/../database/migrations' => database_path('migrations')], 'migrations');
55
56
        // publish seeder
57
        $this->publishes([__DIR__.'/../database/seeds' => database_path('seeds')], 'seeder');
58
59
        // publish factory
60
        $this->publishes([__DIR__.'/../database/factories' => database_path('factories')], 'factories');
61
    }
62
63
    /**
64
     * Define the routes for the application.
65
     *
66
     * @param \Illuminate\Routing\Router $router
67
     *
68
     * @return void
69
     */
70
    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...
71
    {
72
        // by default, use the routes file provided in vendor
73
        $routeFilePathInUse = __DIR__.$this->routeFilePath;
74
75
        // but if there's a file with the same name in routes/webfactor, use that one
76
        if (file_exists(base_path().$this->routeFilePath)) {
77
            $routeFilePathInUse = base_path().$this->routeFilePath;
78
        }
79
80
        $this->loadRoutesFrom($routeFilePathInUse);
81
    }
82
}
83