Test Failed
Push — master ( b71800...c22dc2 )
by Stephen
01:29 queued 11s
created

TrackTraffic::setRequestMethodAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Sfneal\Tracking\Models;
4
5
use Database\Factories\TrackTrafficFactory;
6
use Illuminate\Database\Eloquent\Builder;
7
use Illuminate\Database\Eloquent\Factories\HasFactory;
8
use Illuminate\Database\Eloquent\Relations\BelongsTo;
9
use Sfneal\Helpers\Laravel\AppInfo;
10
use Sfneal\Tracking\Builders\TrackTrafficBuilder;
11
use Sfneal\Tracking\Models\Base\Tracking;
12
13
class TrackTraffic extends Tracking
14
{
15
    use HasFactory;
16
17
    protected $table = 'track_traffic';
18
    protected $primaryKey = 'track_traffic_id';
19
20
    protected $fillable = [
21
        'track_traffic_id',
22
        'user_id',
23
        'session_id',
24
        'app_version',
25
        'app_environment',
26
        'request_host',
27
        'request_uri',
28
        'request_method',
29
        'request_payload',
30
        'request_browser',
31
        'request_ip',
32
        'request_referrer',
33
        'request_token',
34
        'response_code',
35
        'response_time',
36
        'response_content',
37
        'agent_platform',
38
        'agent_device',
39
        'agent_browser',
40
        'time_stamp',
41
    ];
42
43
    /**
44
     * The attributes that should be cast to native types.
45
     *
46
     * @var array
47
     */
48
    protected $casts = [
49
        'user_id' => 'int',
50
        'request_payload' => 'array',
51
        'response_code' => 'int',
52
        'response_time' => 'float',
53
    ];
54
55
    /**
56
     * Create a new factory instance for the model.
57
     *
58
     * @return TrackTrafficFactory
59
     */
60
    protected static function newFactory(): TrackTrafficFactory
61
    {
62
        return new TrackTrafficFactory();
63
    }
64
65
    /**
66
     * Query Builder.
67
     *
68
     * @param $query
69
     *
70
     * @return TrackTrafficBuilder
71
     */
72
    public function newEloquentBuilder($query)
73
    {
74
        return new TrackTrafficBuilder($query);
75
    }
76
77
    /**
78
     * @return TrackTrafficBuilder|Builder
79
     */
80
    public static function query(): TrackTrafficBuilder
81
    {
82
        return parent::query();
83
    }
84
85
    /**
86
     * Tracked activity that is associated with this traffic record.
87
     *
88
     * @return BelongsTo
89
     */
90
    public function activity()
91
    {
92
        return $this->belongsTo(TrackActivity::class, 'request_token', 'request_token');
93
    }
94
95
    /**
96
     * Set the `app_environment` attribute.
97
     *
98
     * @param null $value
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $value is correct as it would always require null to be passed?
Loading history...
99
     */
100
    public function setAppEnvironmentAttribute($value = null)
101
    {
102
        $this->attributes['app_environment'] = $value ?? AppInfo::env();
103
    }
104
105
    /**
106
     * Set the 'request_method' attribute.
107
     *
108
     * @param string|null $value
109
     */
110
    public function setRequestMethodAttribute(string $value = null)
111
    {
112
        $this->attributes['request_method'] = strtoupper($value);
0 ignored issues
show
Bug introduced by
It seems like $value can also be of type null; however, parameter $string of strtoupper() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

112
        $this->attributes['request_method'] = strtoupper(/** @scrutinizer ignore-type */ $value);
Loading history...
113
    }
114
}
115