UrlServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 6
rs 9.4286
c 2
b 0
f 1
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Luminark\Url;
4
5
use Illuminate\Support\ServiceProvider;
6
use Luminark\Url\Interfaces\HasUrlInterface;
7
8
class UrlServiceProvider extends ServiceProvider
9
{
10
    public function boot()
11
    {
12
        $this->publishes([
13
            __DIR__ . '/../database/migrations/' => database_path('migrations')
14
        ], 'migrations');
15
    }
16
    
17
    public function register()
18
    {
19
        $this->app['events']->listen('eloquent.saved*', function ($model) {
20
            if ($model instanceof HasUrlInterface) {
21
                $model->saveUri();
22
            }
23
        });
24
        
25
        $this->app['events']->listen('eloquent.deleted*', function ($model) {
26
            if ($model instanceof HasUrlInterface && $model->url) {
1 ignored issue
show
Bug introduced by
Accessing url on the interface Luminark\Url\Interfaces\HasUrlInterface 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
                $model->url->delete();
1 ignored issue
show
Bug introduced by
Accessing url on the interface Luminark\Url\Interfaces\HasUrlInterface 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...
28
            }
29
        });
30
    }
31
}
32