HasForms   A
last analyzed

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 bootHasForms() 0 6 1
A forms() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Forms\Traits;
6
7
use Illuminate\Database\Eloquent\Relations\MorphMany;
8
9
trait HasForms
10
{
11
    /**
12
     * Register a deleted model event with the dispatcher.
13
     *
14
     * @param \Closure|string $callback
15
     *
16
     * @return void
17
     */
18
    abstract public static function deleted($callback);
19
20
    /**
21
     * Define a polymorphic one-to-many relationship.
22
     *
23
     * @param string $related
24
     * @param string $name
25
     * @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...
26
     * @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...
27
     * @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...
28
     *
29
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
30
     */
31
    abstract public function morphMany($related, $name, $type = null, $id = null, $localKey = null);
32
33
    /**
34
     * Boot the HasForms trait for the model.
35
     *
36
     * @return void
37
     */
38
    public static function bootHasForms()
39
    {
40
        static::deleted(function (self $model) {
41
            $model->forms()->delete();
42
        });
43
    }
44
45
    /**
46
     * Get all attached forms to the model.
47
     *
48
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
49
     */
50
    public function forms(): MorphMany
51
    {
52
        return $this->morphMany(config('rinvex.forms.models.form'), 'entity');
53
    }
54
}
55