FunctionsTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testDos2DateTime() 0 6 2
A testDateTime2Dos() 0 14 3
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