Completed
Push — master ( f0c87c...18719e )
by Jeremy
65:09
created

Activity::getUserAgentDetailsAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace jeremykenedy\LaravelLogger\App\Models;
4
5
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...
6
use Illuminate\Database\Eloquent\SoftDeletes;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Eloquent\SoftDeletes 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
8
class Activity extends Model
9
{
10
    use SoftDeletes;
11
12
    /**
13
     * The table associated with the model.
14
     *
15
     * @var string
16
     */
17
    protected $table;
18
19
    /**
20
     * The connection name for the model.
21
     *
22
     * @var string
23
     */
24
    protected $connection;
25
26
    /**
27
     * Indicates if the model should be timestamped.
28
     *
29
     * @var bool
30
     */
31
    public $timestamps = true;
32
33
    /**
34
     * The attributes that are not mass assignable.
35
     *
36
     * @var array
37
     */
38
    protected $guarded = [
39
        'id',
40
    ];
41
42
    /**
43
     * The attributes that should be mutated to dates.
44
     *
45
     * @var array
46
     */
47
    protected $dates = [
48
        'created_at',
49
        'updated_at',
50
        'deleted_at',
51
    ];
52
53
    /**
54
     * Fillable fields for a Profile.
55
     *
56
     * @var array
57
     */
58
    protected $fillable = [
59
        'description',
60
        'userType',
61
        'userId',
62
        'route',
63
        'ipAddress',
64
        'userAgent',
65
        'locale',
66
        'referer',
67
        'methodType',
68
    ];
69
70
    protected $casts = [
71
        'description'   => 'string',
72
        'user'          => 'integer',
73
        'route'         => 'string',
74
        'ipAddress'     => 'ipAddress',
75
        'userAgent'     => 'string',
76
        'locale'        => 'string',
77
        'referer'       => 'string',
78
        'methodType'    => 'string',
79
    ];
80
81
    /**
82
     * Create a new instance to set the table and connection.
83
     *
84
     * @return void
85
     */
86
    public function __construct($attributes = [])
87
    {
88
        parent::__construct($attributes);
89
        $this->table = config('LaravelLogger.loggerDatabaseTable');
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

89
        $this->table = /** @scrutinizer ignore-call */ config('LaravelLogger.loggerDatabaseTable');
Loading history...
90
        $this->connection = config('LaravelLogger.loggerDatabaseConnection');
91
    }
92
93
    /**
94
     * Get the database connection.
95
     */
96
    public function getConnectionName()
97
    {
98
        return $this->connection;
99
    }
100
101
    /**
102
     * Get the database connection.
103
     */
104
    public function getTableName()
105
    {
106
        return $this->table;
107
    }
108
109
    /**
110
     * An activity has a user.
111
     *
112
     * @var array
113
     */
114
    public function user()
115
    {
116
        return $this->hasOne(config('LaravelLogger.defaultUserModel'));
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

116
        return $this->hasOne(/** @scrutinizer ignore-call */ config('LaravelLogger.defaultUserModel'));
Loading history...
117
    }
118
119
    /**
120
     * Get a validator for an incoming Request.
121
     *
122
     * @param array $merge (rules to optionally merge)
123
     *
124
     * @return array
125
     */
126
    public static function rules($merge = [])
127
    {
128
        return array_merge(
129
            [
130
                'description'   => 'required|string',
131
                'userType'      => 'required|string',
132
                'userId'        => 'nullable|integer',
133
                'route'         => 'nullable|url',
134
                'ipAddress'     => 'nullable|ip',
135
                'userAgent'     => 'nullable|string',
136
                'locale'        => 'nullable|string',
137
                'referer'       => 'nullable|string',
138
                'methodType'    => 'nullable|string',
139
            ],
140
            $merge
141
        );
142
    }
143
144
    /**
145
     * User Agent Parsing Helper
146
     *
147
     * @return String
148
     */
149
    public function getUserAgentDetailsAttribute()
150
    {
151
        return \jeremykenedy\LaravelLogger\App\Http\Traits\UserAgentDetails::details($this->userAgent);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 103 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
152
    }
153
154
}
155