ObserverServiceProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 1
A boot() 0 6 1
1
<?php
2
3
namespace App\Providers;
4
5
use App\Category;
6
use App\Image;
7
use App\Listeners\Observers\CategoryObserver;
8
use App\Listeners\Observers\ImageObserver;
9
use App\Listeners\Observers\ProductObserver;
10
use App\Listeners\Observers\SubCategoryObserver;
11
use App\Listeners\Observers\TagObserver;
12
use App\Listeners\Observers\VendorsObserver;
13
use App\Product;
14
use App\Vendor;
15
use App\SubCategory;
16
use App\Tag;
17
use Illuminate\Support\ServiceProvider;
18
19
class ObserverServiceProvider extends ServiceProvider
20
{
21
    /**
22
     * List of observers which belongs to models
23
     *
24
     * @var array
25
     */
26
    protected $observers = [
27
        Image::class => ImageObserver::class,
28
        Product::class => ProductObserver::class,
29
        Category::class => CategoryObserver::class,
30
        SubCategory::class => SubCategoryObserver::class,
31
        Tag::class => TagObserver::class,
32
        Vendor::class => VendorsObserver::class
33
    ];
34
35
    /**
36
     * Register observers.
37
     *
38
     * @return void.
0 ignored issues
show
Documentation introduced by
The doc-type void. could not be parsed: Unknown type name "void." at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
39
     */
40
    public function register()
41
    {
42
        //
43
    }
44
45
    /**
46
     * Registering observers SHOULD BE in boot() method.
47
     * 
48
     * @return void.
0 ignored issues
show
Documentation introduced by
The doc-type void. could not be parsed: Unknown type name "void." at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
49
     */
50
    public function boot()
51
    {
52
        array_walk($this->observers, function ($observer, $model) {
53
            $model::observe(new $observer);
54
        });
55
    }
56
}