FunctionsTest::testDos2DateTime()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace morgue\zip;
4
5
use PHPUnit\Framework\TestCase;
6
7
class FunctionsTest extends TestCase
8
{
9
    private $cases = [
10
        [0, 0, "1979-11-30 00:00:00", "1979-11-30 00:00:01"],
11
        [1, 0, "1979-11-30 00:00:02", "1979-11-30 00:00:03"],
12
        [0, 33, "1980-01-01 00:00:00"],
13
        [43507, 19583, "2018-03-31 21:15:38"],
14
    ];
15
16
17
    /**
18
     * @throws \Exception
19
     */
20
    public function testDos2DateTime()
21
    {
22
        foreach ($this->cases as list($dosTime, $dosDate, $datetime)) {
23
            $this->assertEquals(new \DateTimeImmutable($datetime), dos2DateTime($dosTime, $dosDate));
24
        }
25
    }
26
27
    /**
28
     * @throws \Exception
29
     */
30
    public function testDateTime2Dos()
31
    {
32
        foreach ($this->cases as $caseIndex => list($dosTime, $dosDate)) {
33
            for ($i=2; $i<\count($this->cases[$caseIndex]); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
34
                $datetime = $this->cases[$caseIndex][$i];
35
                $this->assertEquals(DateTime2dos(new \DateTimeImmutable($datetime)), [
36
                    $dosTime,
37
                    $dosDate,
38
                    'time' => $dosTime,
39
                    'date' => $dosDate,
40
                ], $datetime);
41
            }
42
        }
43
    }
44
}
45