Passed
Push — master ( 5a03f9...8e29e6 )
by Stephen
03:56 queued 01:10
created

ModelEvents::trackingEventModel()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
4
namespace Sfneal\CrudModelActions\Utils;
5
6
7
use Illuminate\Database\Eloquent\Model;
8
use Sfneal\Models\AbstractModel;
9
use Support\Tracking\Events\TrackActivityEvent;
0 ignored issues
show
Bug introduced by
The type Support\Tracking\Events\TrackActivityEvent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
trait ModelEvents
12
{
13
    /**
14
     * @var string Tracking Event to fire
15
     */
16
    protected $trackingEvent = TrackActivityEvent::class;
17
18
    /**
19
     * @var AbstractModel|Model
20
     */
21
    private $trackingEventModel;
22
23
    /**
24
     * Fire the trackingEvent
25
     *
26
     * @return void
27
     */
28
    protected function fireEvent()
29
    {
30
        event(new $this->trackingEvent($this->trackingEventModel()));
31
    }
32
33
    /**
34
     * Retrieve the Model to be used in the fireEvent() method
35
     *
36
     *  - optionally set a the $trackingEventModel property
37
     *  - useful for using a different model in the trackingEvent than the resolved/saved model
38
     *
39
     * @param Model|null $model
40
     * @return AbstractModel|Model
41
     */
42
    protected function trackingEventModel(Model $model = null): Model
43
    {
44
        if (isset($model)) {
45
            $this->trackingEventModel = $model;
46
        }
47
48
        return $this->trackingEventModel ?? $this->model;
49
    }
50
}
51