Completed
Pull Request — master (#309)
by
unknown
03:29
created

Result::getMicroElapsed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Ddeboer\DataImport;
4
5
use Ddeboer\DataImport\Exception\ExceptionInterface;
6
7
/**
8
 * Simple Container for Workflow Results
9
 *
10
 * @author Aydin Hassan <[email protected]>
11
 */
12
class Result
13
{
14
    const MICRO_FORMAT = 'd-m-Y H:i:s.u';
15
    /**
16
     * Identifier given to the import/export
17
     *
18
     * @var string
19
     */
20
    protected $name;
21
22
    /**
23
     * @var \DateTime
24
     */
25
    protected $startTime;
26
27
    /**
28
     * @var \DateTime
29
     */
30
    protected $endTime;
31
32
    /**
33
     * @var \DateInterval
34
     */
35
    protected $elapsed;
36
37
    /**
38
     * @var integer
39
     */
40
    protected $errorCount = 0;
41
42
    /**
43
     * @var integer
44
     */
45
    protected $successCount = 0;
46
47
    /**
48
     * @var integer
49
     */
50
    protected $totalProcessedCount = 0;
51
52
    /**
53
     * @var \SplObjectStorage
54
     */
55
    protected $exceptions;
56
57
    /**
58
     * @param string            $name
59
     * @param \DateTime         $startTime
60
     * @param \DateTime         $endTime
61
     * @param integer           $totalCount
62
     * @param \SplObjectStorage $exceptions
63
     */
64 16
    public function __construct($name, \DateTime $startTime, \DateTime $endTime, $totalCount, \SplObjectStorage $exceptions)
65
    {
66 16
        $this->name                = $name;
67 16
        $this->startTime           = $startTime;
68 16
        $this->endTime             = $endTime;
69 16
        $this->elapsed             = $startTime->diff($endTime);
70 16
        $this->totalProcessedCount = $totalCount;
71 16
        $this->errorCount          = count($exceptions);
72 16
        $this->successCount        = $totalCount - $this->errorCount;
73 16
        $this->exceptions          = $exceptions;
74 16
    }
75
76
    /**
77
     * @return string
78
     */
79 2
    public function getName()
80
    {
81 2
        return $this->name;
82
    }
83
84
    /**
85
     * @return \DateTime
86
     */
87 2
    public function getStartTime()
88
    {
89 2
        return $this->startTime;
90
    }
91
92
    /**
93
     * @return \DateTime
94
     */
95 2
    public function getEndTime()
96
    {
97 2
        return $this->endTime;
98
    }
99
100
    /**
101
     * @return \DateInterval
102
     */
103 2
    public function getElapsed()
104
    {
105 2
        return $this->elapsed;
106
    }
107
108
    /**
109
     * @return integer
110
     */
111 2
    public function getErrorCount()
112
    {
113 2
        return $this->errorCount;
114
    }
115
116
    /**
117
     * @return integer
118
     */
119 2
    public function getSuccessCount()
120
    {
121 2
        return $this->successCount;
122
    }
123
124
    /**
125
     * @return integer
126
     */
127 2
    public function getTotalProcessedCount()
128
    {
129 2
        return $this->totalProcessedCount;
130
    }
131
132
    /**
133
     * @return boolean
134
     */
135 3
    public function hasErrors()
136
    {
137 3
        return $this->errorCount > 0;
138
    }
139
140
    /**
141
     * @return \SplObjectStorage
142
     */
143 2
    public function getExceptions()
144
    {
145 2
        return $this->exceptions;
146
    }
147
148
    /**
149
     * find the elapsed microseconds for the result. This only finds the microsecond difference, use {@link getElapsed()}
150
     *
151
     * @return number
152
     */
153 1
    public function getMicroElapsed()
154
    {
155 1
        $microStart = $this->startTime->format('u');
156 1
        $microEnd = $this->endTime->format('u');
157 1
        $microDiff = abs($microEnd - $microStart);
158
159 1
        return $microDiff;
160
    }
161
}
162