AuditsService   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A log() 0 34 2
1
<?php
2
3
namespace Audit\Services;
4
5
use Carbon\Carbon;
6
use Illuminate\Support\Facades\Schema;
7
use Audit\Models\Audits;
8
9
class AuditsService
10
{
11
    public function __construct(Audits $model)
12
    {
13
        $this->model = $model;
0 ignored issues
show
Bug introduced by
The property model does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
14
    }
15
16
    public function log($request)
17
    {
18
        $requestData = json_encode(
19
            [
20
            'referer' => $request->server('HTTP_REFERER', null),
21
            'user_agent' => $request->server('HTTP_USER_AGENT', null),
22
            'host' => $request->server('HTTP_HOST', null),
23
            'remote_addr' => $request->server('REMOTE_ADDR', null),
24
            'uri' => $request->server('REQUEST_URI', null),
25
            'method' => $request->server('REQUEST_METHOD', null),
26
            'query' => $request->server('QUERY_STRING', null),
27
            'time' => $request->server('REQUEST_TIME', null),
28
            ]
29
        );
30
31
        $route = 'todo/Route';
32
        $business = 0;
33
        $user = 0;
34
35
        /**
36
         * @todo data faltando
37
         */
38
        $requestData = md5($requestData);
39
        if (Schema::hasTable('audits')) {
40
            $this->model->create(
41
                [
42
                'route' => $route,
43
                'business' => $business,
44
                'user' => $user,
45
                'data' => $requestData,
46
                ]
47
            );
48
        }
49
    }
50
}
51