Json   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A printResults() 0 21 2
1
<?php
2
3
namespace Lloople\PHPUnitExtensions\Runners\SlowestTests;
4
5
class Json extends Channel
6
{
7
    /**
8
     * The name of the file to store the output.
9
     *
10
     * @var string
11
     */
12
    protected $file;
13
    
14
    public function __construct(string $file = 'phpunit_results.json', ?int $rows = null, ?int $min = 200)
15
    {
16
        parent::__construct($rows, $min);
17
18
        $this->file = $file;
19
    }
20
21
    protected function printResults(): void
22
    {
23
        $stream = fopen($this->file, 'w');
24
25
        $json = [];
26
27
        foreach ($this->testsToPrint() as $test => $time) {
28
            [$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...
29
30
            $json[] = [
31
                'time' => $time,
32
                'method' => $method,
33
                'class' => $class,
34
                'name' => $test
35
            ];
36
        }
37
38
        fwrite($stream, json_encode($json, JSON_PRETTY_PRINT));
39
40
        fclose($stream);
41
    }
42
}