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

Json   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A printResults() 0 21 2
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
}