Completed
Push — master ( 81e1d8...617a2d )
by Alessandro
63:04 queued 06:11
created

Query::setReadPreference()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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