Completed
Push — develop ( 9db14c...3f0e2c )
by Abdelrahman
02:51
created

HasContacts   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
deleted() 0 1 ?
morphMany() 0 1 ?
A bootHasContacts() 0 6 1
A contacts() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Contacts\Traits;
6
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Database\Eloquent\Relations\MorphMany;
9
10
trait HasContacts
11
{
12
    /**
13
     * Register a deleted model event with the dispatcher.
14
     *
15
     * @param \Closure|string $callback
16
     *
17
     * @return void
18
     */
19
    abstract public static function deleted($callback);
20
21
    /**
22
     * Define a polymorphic one-to-many relationship.
23
     *
24
     * @param string $related
25
     * @param string $name
26
     * @param string $type
0 ignored issues
show
Documentation introduced by
Should the type for parameter $type not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
27
     * @param string $id
0 ignored issues
show
Documentation introduced by
Should the type for parameter $id not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
28
     * @param string $localKey
0 ignored issues
show
Documentation introduced by
Should the type for parameter $localKey not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
29
     *
30
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
31
     */
32
    abstract public function morphMany($related, $name, $type = null, $id = null, $localKey = null);
33
34
    /**
35
     * Boot the HasContacts trait for the model.
36
     *
37
     * @return void
38
     */
39
    public static function bootHasContacts()
40
    {
41
        static::deleted(function (self $model) {
42
            $model->contacts()->delete();
43
        });
44
    }
45
46
    /**
47
     * Get all attached contacts to the model.
48
     *
49
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
50
     */
51
    public function contacts(): MorphMany
52
    {
53
        return $this->morphMany(config('rinvex.contacts.models.contact'), 'entity');
54
    }
55
}
56