Completed
Push — master ( fba3d3...d8ef55 )
by Alessandro
02:14
created

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