Completed
Pull Request — master (#11)
by Alessandro
03:04
created

LogEvent   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 94.74%

Importance

Changes 0
Metric Value
wmc 13
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 124
ccs 36
cts 38
cp 0.9474
rs 10

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getStart() 0 4 1
A setStart() 0 4 1
A getCollection() 0 4 1
A setCollection() 0 4 1
A getMethod() 0 4 1
A setMethod() 0 4 1
A getFilters() 0 4 1
A setFilters() 0 4 1
A getData() 0 4 1
A setData() 0 4 1
A getExecutionTime() 0 4 1
A setExecutionTime() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\MongoDbBundle\Models;
6
7
/**
8
 * Class LogEvent.
9
 */
10
class LogEvent
11
{
12
    /** @var float */
13
    private $start;
14
    /** @var string */
15
    private $method;
16
    /** @var string */
17
    private $collection;
18
    /** @var array */
19
    private $filters;
20
    /** @var array */
21
    private $data;
22
    /** @var int */
23
    private $executionTime;
24
25
    /**
26
     * LogEvent constructor.
27
     */
28 13
    public function __construct()
29
    {
30 13
        $this->start = 0.0;
31 13
        $this->collection = 'undefined';
32 13
        $this->method = 'undefined';
33 13
        $this->filters = [];
34 13
        $this->data = [];
35 13
        $this->executionTime = 0;
36 13
    }
37
38
    /**
39
     * @return float
40
     */
41 3
    public function getStart(): float
42
    {
43 3
        return $this->start;
44
    }
45
46
    /**
47
     * @param float $start
48
     */
49 1
    public function setStart(float $start)
50
    {
51 1
        $this->start = $start;
52 1
    }
53
54
    /**
55
     * @return string
56
     */
57 1
    public function getCollection(): string
58
    {
59 1
        return $this->collection;
60
    }
61
62
    /**
63
     * @param string $collection
64
     */
65 10
    public function setCollection(string $collection)
66
    {
67 10
        $this->collection = $collection;
68 10
    }
69
70
    /**
71
     * @return string
72
     */
73 1
    public function getMethod(): string
74
    {
75 1
        return $this->method;
76
    }
77
78
    /**
79
     * @param string $method
80
     */
81 9
    public function setMethod(string $method)
82
    {
83 9
        $this->method = $method;
84 9
    }
85
86
    /**
87
     * @return array
88
     */
89
    public function getFilters(): array
90
    {
91
        return $this->filters;
92
    }
93
94
    /**
95
     * @param array $filters
96
     */
97 8
    public function setFilters($filters)
98
    {
99 8
        $this->filters = $filters ?? [];
100 8
    }
101
102
    /**
103
     * @return array|object
104
     */
105 1
    public function getData()
106
    {
107 1
        return $this->data;
108
    }
109
110
    /**
111
     * @param array|object $data
112
     */
113 10
    public function setData($data)
114
    {
115 10
        $this->data = $data ?? [];
0 ignored issues
show
Documentation Bug introduced by
It seems like $data ?? array() can also be of type object. However, the property $data is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
116 10
    }
117
118
    /**
119
     * @return float
120
     */
121 3
    public function getExecutionTime(): float
122
    {
123 3
        return $this->executionTime;
124
    }
125
126
    /**
127
     * @param float $executionTime
128
     */
129 3
    public function setExecutionTime(float $executionTime)
130
    {
131 3
        $this->executionTime = $executionTime;
0 ignored issues
show
Documentation Bug introduced by
The property $executionTime was declared of type integer, but $executionTime is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
132 3
    }
133
}
134