Completed
Push — master ( 349402...ef2f42 )
by David
01:07
created

Json::printResults()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Lloople\PHPUnitExtensions\Runners\SlowestTests;
4
5
class Json extends Channel
6
{
7
    protected $file;
8
    
9
    public function __construct(int $rows = 5, string $file = 'phpunit_results.json')
10
    {
11
        $this->rows = $rows;
12
        $this->file = $file;
13
    }
14
15
    protected function printResults(): void
16
    {
17
        $stream = fopen($this->file, 'w');
18
19
        $json = [];
20
21
        foreach ($this->testsToPrint() as $test => $time) {
22
            [$class, $method] = explode('::', $test);
0 ignored issues
show
Bug introduced by
The variable $class does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $method does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
23
24
            $json[] = [
25
                'time' => $time,
26
                'method' => $method,
27
                'class' => $class,
28
                'name' => $test
29
            ];
30
        }
31
32
        fwrite($stream, json_encode($json, JSON_PRETTY_PRINT));
33
34
        fclose($stream);
35
    }
36
}