ImportResult::getSuccess()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

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
nc 1
nop 0
crap 1
1
<?php
2
3
namespace TreeHouse\IoBundle\Import;
4
5
class ImportResult
6
{
7
    /**
8
     * @var int
9
     */
10
    protected $startTime;
11
12
    /**
13
     * @var int
14
     */
15
    protected $endTime;
16
17
    /**
18
     * @var int
19
     */
20
    protected $success = 0;
21
22
    /**
23
     * @var int
24
     */
25
    protected $failed = 0;
26
27
    /**
28
     * @var int
29
     */
30
    protected $skipped = 0;
31
32
    /**
33
     * @param int $startTime
34
     */
35 6
    public function __construct($startTime = null)
36
    {
37 6
        $this->startTime = $startTime ?: microtime(true);
0 ignored issues
show
Documentation Bug introduced by
It seems like $startTime ?: microtime(true) can also be of type double. However, the property $startTime is declared as type integer. 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...
38 6
    }
39
40
    /**
41
     * @return int
42
     */
43
    public function getStartTime()
44
    {
45
        return $this->startTime;
46
    }
47
48
    /**
49
     * @param int $startTime
50
     */
51
    public function setStartTime($startTime)
52
    {
53
        $this->startTime = $startTime;
54
    }
55
56
    /**
57
     * @return int
58
     */
59
    public function getEndTime()
60
    {
61
        return $this->endTime;
62
    }
63
64
    /**
65
     * @param int $endTime
66
     */
67
    public function setEndTime($endTime)
68
    {
69
        $this->endTime = $endTime;
70
    }
71
72
    /**
73
     * Adds 1 to success.
74
     */
75 4
    public function incrementSuccess()
76
    {
77 4
        ++$this->success;
78 4
    }
79
80
    /**
81
     * @param int $success
82
     */
83
    public function setSuccess($success)
84
    {
85
        $this->success = $success;
86
    }
87
88
    /**
89
     * @return int
90
     */
91 4
    public function getSuccess()
92
    {
93 4
        return $this->success;
94
    }
95
96
    /**
97
     * Adds 1 to failed.
98
     */
99 4
    public function incrementFailed()
100
    {
101 4
        ++$this->failed;
102 4
    }
103
104
    /**
105
     * @param int $failed
106
     */
107
    public function setFailed($failed)
108
    {
109
        $this->failed = $failed;
110
    }
111
112
    /**
113
     * @return int
114
     */
115 4
    public function getFailed()
116
    {
117 4
        return $this->failed;
118
    }
119
120
    /**
121
     * @return int
122
     */
123 4
    public function getSkipped()
124
    {
125 4
        return $this->skipped;
126
    }
127
128
    /**
129
     * @param int $skipped
130
     */
131
    public function setSkipped($skipped)
132
    {
133
        $this->skipped = $skipped;
134
    }
135
136
    /**
137
     * Adds 1 to skipped.
138
     */
139 4
    public function incrementSkipped()
140
    {
141 4
        ++$this->skipped;
142 4
    }
143
144
    /**
145
     * Returns the total number of items that were in the feed, whether they were processed or skipped.
146
     *
147
     * @return int
148
     */
149
    public function getTotal()
150
    {
151
        return $this->getSkipped() + $this->getProcessed();
152
    }
153
154
    /**
155
     * Returns the number of items that were actually handled by the import, as opposed to skipped items.
156
     *
157
     * @return int
158
     */
159 4
    public function getProcessed()
160
    {
161 4
        return $this->getSuccess() + $this->getFailed();
162
    }
163
164
    /**
165
     * @return float
166
     */
167
    public function getElapsedTime()
168
    {
169
        return microtime(true) - $this->startTime;
170
    }
171
}
172