Issues (3)

src/CascadeDelete.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Cesargb\Database\Support;
4
5
trait CascadeDelete
6
{
7
    /**
8
     * Boot the trait.
9
     *
10
     * Listen for the deleted event of a model, and run
11
     * the delete operation for morphs configured relationship methods.
12
     */
13
    protected static function bootCascadeDelete()
14
    {
15
        static::deleted(function ($model) {
16
            $morph = new Morph();
17
18
            $morph->delete($model);
19
        });
20
    }
21
22
    /**
23
     * Fetch methods name than must return a morph relation.
24
     *
25
     * @return string[]
26
     */
27
    public function getCascadeDeleteMorph()
28
    {
29
        return (array) ($this->cascadeDeleteMorph ?? []);
30
    }
31
32
    /**
33
     * Clean residual morph relation from a model. Return number
34
     * of deleted rows.
35
     *
36
     * @param  bool  $dryRun
37
     * @return int
38
     */
39
    public function deleteMorphResidual(bool $dryRun = false)
40
    {
41
        return (new Morph())->cleanResidualByModel($this, $dryRun);
0 ignored issues
show
$this of type Cesargb\Database\Support\CascadeDelete is incompatible with the type Illuminate\Database\Eloquent\Model expected by parameter $model of Cesargb\Database\Support...:cleanResidualByModel(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
        return (new Morph())->cleanResidualByModel(/** @scrutinizer ignore-type */ $this, $dryRun);
Loading history...
42
    }
43
}
44