ApiLog   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 7 1
A __construct() 0 8 3
1
<?php
2
3
namespace Sarahman\HttpRequestApiLog\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Sarahman\HttpRequestApiLog\Helper;
7
8
/**
9
 * This model deals with Http API calls logging.
10
 *
11
 * @property int                 $id
12
 * @property string              $client
13
 * @property string              $method
14
 * @property string              $endpoint
15
 * @property string              $params
16
 * @property int|null            $response_code
17
 * @property string|null         $response
18
 * @property \Carbon\Carbon|null $created_at
19
 * @property \Carbon\Carbon|null $updated_at
20
 */
21
class ApiLog extends Model
22
{
23
    /**
24
     * @inheritDoc
25
     */
26
    protected $guarded = [];
27
28
    public function __construct(array $attributes = [])
29
    {
30
        $config = Helper::getConfig();
31
32
        isset($this->connection) || $this->setConnection($config['database_connection']);
33
        isset($this->table) || $this->setTable($config['table_name']);
34
35
        parent::__construct($attributes);
36
    }
37
38
    /**
39
     * @inheritDoc
40
     */
41
    protected static function boot()
42
    {
43
        parent::boot();
44
45
        self::creating(function (self $model) {
46
            $model->method = strtoupper($model->method);
47
            $model->params = json_encode($model->params);
48
        });
49
    }
50
}
51