NestedModelsServiceProvider::publish()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Webfactor\Laravel\Backpack\NestedModels;
4
5
use Illuminate\Database\Schema\Blueprint;
6
use Illuminate\Routing\Router;
7
use Illuminate\Support\ServiceProvider;
8
9
class NestedModelsServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Perform post-registration booting of services.
13
     *
14
     * @return void
15
     */
16
    public function boot()
17
    {
18
        // LOAD THE VIEWS
19
        $this->loadViewsFrom(resource_path('views/vendor/webfactor/nestedmodels'), 'nestedmodels');
20
        $this->loadViewsFrom(realpath(__DIR__.'/../views'), 'nestedmodels');
21
22
        $this->macros();
23
24
        $this->publish();
25
26
        // AUTO PUBLISH
27
        if (\App::environment('local')) {
28
            if ($this->shouldAutoPublishPublic()) {
29
                \Artisan::call('vendor:publish', [
30
                    '--provider' => 'Backpack\CRUD\CrudServiceProvider',
31
                    '--tag' => 'public',
32
                ]);
33
            }
34
        }
35
    }
36
37
    /**
38
     * Register any package services.
39
     *
40
     * @return void
41
     */
42
    public function register()
43
    {
44
        //
45
    }
46
47
    public function publish()
48
    {
49
        $this->publishes([__DIR__.'/../views' => resource_path('views/vendor/webfactor/nestedmodels')], 'views');
50
51
        $this->publishes([__DIR__.'/../public' => public_path('vendor/webfactor/nestedmodels')], 'public');
52
    }
53
54
55
    public function macros()
56
    {
57
        Blueprint::macro('tree', function () {
58
            $this->unsignedInteger('parent_id')->nullable()->index();
0 ignored issues
show
Bug introduced by
The method unsignedInteger() does not seem to exist on object<Webfactor\Laravel...dModelsServiceProvider>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
59
            $this->unsignedInteger('lft')->default(0)->index();
0 ignored issues
show
Bug introduced by
The method unsignedInteger() does not seem to exist on object<Webfactor\Laravel...dModelsServiceProvider>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
            $this->unsignedInteger('rgt')->default(0)->index();
0 ignored issues
show
Bug introduced by
The method unsignedInteger() does not seem to exist on object<Webfactor\Laravel...dModelsServiceProvider>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
            $this->unsignedInteger('depth')->default(0);
0 ignored issues
show
Bug introduced by
The method unsignedInteger() does not seem to exist on object<Webfactor\Laravel...dModelsServiceProvider>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
62
63
            $this->foreign('parent_id')->references('id')->on($this->table)
0 ignored issues
show
Bug introduced by
The property table does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
The method foreign() does not seem to exist on object<Webfactor\Laravel...dModelsServiceProvider>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
                ->onUpdate('cascade')->onDelete('cascade');
65
        });
66
    }
67
68
    /**
69
     * Checks to see if we should automatically publish
70
     * vendor files from the public tag.
71
     *
72
     * @return bool
73
     */
74
    private function shouldAutoPublishPublic()
75
    {
76
        $crudPubPath = public_path('vendor/webfactor/nestedmodels');
77
78
        return ! is_dir($crudPubPath);
79
    }
80
}
81