Completed
Push — master ( a6c7fa...da0e22 )
by Abdelrahman
04:13
created

HasTestimonials::bootHasTestimonials()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Testimonials\Traits;
6
7
use Illuminate\Database\Eloquent\Relations\HasMany;
8
9
trait HasTestimonials
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 one-to-many relationship.
22
     *
23
     * @param  string  $related
24
     * @param  string  $foreignKey
0 ignored issues
show
Documentation introduced by
Should the type for parameter $foreignKey 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...
25
     * @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...
26
     *
27
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
28
     */
29
    abstract public function hasMany($related, $foreignKey = null, $localKey = null);
30
31
    /**
32
     * Boot the HasTestimonials trait for the model.
33
     *
34
     * @return void
35
     */
36
    public static function bootHasTestimonials()
37
    {
38
        static::deleted(function (self $model) {
39
            $model->testimonials()->delete();
40
        });
41
    }
42
43
    /**
44
     * Get all attached testimonials to the model.
45
     *
46
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
0 ignored issues
show
Documentation introduced by
Should the return type not be HasMany?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
47
     */
48
    public function testimonials(): HasMany
49
    {
50
        return $this->hasMany(config('rinvex.testimonials.models.testimonial'), 'user_id', 'id');
51
    }
52
}
53