UrlServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 5
Bugs 0 Features 2
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 24
rs 10
c 5
b 0
f 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 1
A register() 0 14 4
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