Completed
Branch query_logging_to_events (025608)
by Alessandro
02:17
created

QueryLog::getStart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\MongoDbBundle\Models;
6
7
/**
8
 * Class QueryLog.
9
 * @internal
10
 */
11
class QueryLog
12
{
13
    /** @var float */
14
    private $start;
15
    /** @var string */
16
    private $method;
17
    /** @var string */
18
    private $collection;
19
    /** @var array|object */
20
    private $filters;
21
    /** @var array */
22
    private $data;
23
    /** @var array */
24
    private $options;
25
    /** @var int */
26
    private $executionTime;
27
28
    /**
29
     * QueryLog constructor.
30
     */
31 14
    public function __construct()
32
    {
33 14
        $this->start = microtime(true);
34 14
        $this->collection = 'undefined';
35 14
        $this->method = 'undefined';
36 14
        $this->filters = [];
37 14
        $this->data = [];
38 14
        $this->options = [];
39 14
        $this->executionTime = 0;
40 14
    }
41
42
    /**
43
     * @return float
44
     */
45 11
    public function getStart(): float
46
    {
47 11
        return $this->start;
48
    }
49
50
    /**
51
     * @param float $start
52
     */
53
    public function setStart(float $start)
54
    {
55
        $this->start = $start;
56
    }
57
58
    /**
59
     * @return string
60
     */
61 1
    public function getCollection(): string
62
    {
63 1
        return $this->collection;
64
    }
65
66
    /**
67
     * @param string $collection
68
     */
69 13
    public function setCollection(string $collection)
70
    {
71 13
        $this->collection = $collection;
72 13
    }
73
74
    /**
75
     * @return string
76
     */
77 1
    public function getMethod(): string
78
    {
79 1
        return $this->method;
80
    }
81
82
    /**
83
     * @param string $method
84
     */
85 12
    public function setMethod(string $method)
86
    {
87 12
        $this->method = $method;
88 12
    }
89
90
    /**
91
     * @return array
92
     */
93
    public function getFilters(): array
94
    {
95
        return $this->filters;
96
    }
97
98
    /**
99
     * @param array|object $filters
100
     */
101 11
    public function setFilters($filters)
102
    {
103 11
        $this->filters = (array) $filters ?? [];
104 11
    }
105
106
    /**
107
     * @return array|object
108
     */
109 1
    public function getData()
110
    {
111 1
        return $this->data;
112
    }
113
114
    /**
115
     * @param array|object $data
116
     */
117 13
    public function setData($data)
118
    {
119 13
        $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...
120 13
    }
121
122
    /**
123
     * @return array
124
     */
125
    public function getOptions(): array
126
    {
127
        return $this->options;
128
    }
129
130
    /**
131
     * @param array $options
132
     */
133 11
    public function setOptions(array $options)
134
    {
135 11
        $this->options = $options;
136 11
    }
137
138
    /**
139
     * @return float
140
     */
141 2
    public function getExecutionTime(): float
142
    {
143 2
        return $this->executionTime;
144
    }
145
146
    /**
147
     * @param float $executionTime
148
     */
149 12
    public function setExecutionTime(float $executionTime)
150
    {
151 12
        $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...
152 12
    }
153
}
154