Event   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 53
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A user() 0 5 1
A createFromContract() 0 11 1
A model() 0 3 1
1
<?php
2
3
namespace SaasReady\Models;
4
5
use Carbon\Carbon;
0 ignored issues
show
Bug introduced by
The type Carbon\Carbon 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...
6
use Illuminate\Database\Eloquent\Model;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Eloquent\Model 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...
7
use Illuminate\Database\Eloquent\Relations\BelongsTo;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Eloquent\Relations\BelongsTo 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...
8
use Illuminate\Database\Eloquent\Relations\MorphTo;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Eloquent\Relations\MorphTo 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...
9
use SaasReady\Contracts\EventSourcingContract;
10
use SaasReady\Traits\EloquentBuilderMixin;
11
use SaasReady\Traits\HasUuid;
0 ignored issues
show
Bug introduced by
The type SaasReady\Traits\HasUuid 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...
12
13
/**
14
 * @property-read int $id
15
 * @property int $model_id
16
 * @property string $model_type
17
 * @property string $name
18
 * @property string $category
19
 * @property array $properties
20
 * @property int $user_id
21
 * @property ?Carbon $created_at
22
 * @property ?Carbon $updated_at
23
 *
24
 * @property-read Model $model
25
 * @property-read ?Model $user
26
 *
27
 * @mixin EloquentBuilderMixin
28
 */
29
class Event extends Model
30
{
31
    use HasUuid;
32
33
    protected $table = 'events';
34
35
    protected $fillable = [
36
        'name',
37
        'user_id',
38
        'model_id',
39
        'model_type',
40
        'category',
41
        'properties',
42
    ];
43
44
    protected $casts = [
45
        'user_id' => 'int',
46
        'properties' => 'array',
47
    ];
48
49
    /**
50
     * An Event belongsTo a model
51
     */
52
    public function model(): MorphTo
53
    {
54
        return $this->morphTo('model');
55
    }
56
57
    /**
58
     * An Event belongs to a User
59
     */
60
    public function user(): BelongsTo
61
    {
62
        return $this->belongsTo(
63
            config('saas-ready.event-sourcing.user-model'),
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

63
            /** @scrutinizer ignore-call */ 
64
            config('saas-ready.event-sourcing.user-model'),
Loading history...
64
            'user_id'
65
        );
66
    }
67
68
    /**
69
     * Quickly create a new instance from Contract
70
     */
71
    public static function createFromContract(EventSourcingContract $contractor): Event
72
    {
73
        $baseModel = $contractor->getModel();
74
75
        return Event::create([
76
            'name' => class_basename($contractor),
0 ignored issues
show
Bug introduced by
The function class_basename was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

76
            'name' => /** @scrutinizer ignore-call */ class_basename($contractor),
Loading history...
77
            'category' => $contractor->getCategory(),
78
            'properties' => $contractor->getEventProperties(),
79
            'model_id' => $baseModel->getKey(),
80
            'model_type' => $baseModel->getMorphClass(),
81
            'user_id' => $contractor->getUser()?->getKey(),
82
        ]);
83
    }
84
}
85