Issues (28)

src/Models/TrackTraffic.php (2 issues)

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
     * @return TrackTrafficBuilder
70
     */
71
    public function newEloquentBuilder($query)
72
    {
73
        return new TrackTrafficBuilder($query);
74
    }
75
76
    /**
77
     * @return TrackTrafficBuilder|Builder
78
     */
79
    public static function query(): TrackTrafficBuilder
80
    {
81
        return parent::query();
82
    }
83
84
    /**
85
     * Tracked activity that is associated with this traffic record.
86
     *
87
     * @return BelongsTo
88
     */
89
    public function activity()
90
    {
91
        return $this->belongsTo(TrackActivity::class, 'request_token', 'request_token');
92
    }
93
94
    /**
95
     * Set the `app_environment` attribute.
96
     *
97
     * @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...
98
     */
99
    public function setAppEnvironmentAttribute($value = null)
100
    {
101
        $this->attributes['app_environment'] = $value ?? AppInfo::env();
102
    }
103
104
    /**
105
     * Set the 'request_method' attribute.
106
     *
107
     * @param  string|null  $value
108
     */
109
    public function setRequestMethodAttribute(string $value = null)
110
    {
111
        $this->attributes['request_method'] = strtoupper($value);
0 ignored issues
show
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

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