Completed
Push — master ( 501416...580ac7 )
by David
01:23
created

Channel   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 45
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A executeAfterTest() 0 4 1
A timeToMiliseconds() 0 4 1
A executeAfterLastTest() 0 6 1
A sortTestsBySpeed() 0 4 1
printResults() 0 1 ?
A testsToPrint() 0 4 1
A getClassName() 0 4 1
1
<?php
2
3
namespace Lloople\PHPUnitExtensions\Runners\SlowestTests;
4
5
use PHPUnit\Runner\AfterLastTestHook;
6
use PHPUnit\Runner\AfterTestHook;
7
8
abstract class Channel implements AfterTestHook, AfterLastTestHook
9
{
10
    protected $tests = [];
11
12
    protected $rows;
13
14
    public function __construct(int $rows = 5)
15
    {
16
        $this->rows = $rows;
17
    }
18
19
    public function executeAfterTest(string $test, float $time): void
20
    {
21
        $this->tests[$test] = $this->timeToMiliseconds($time);
22
    }
23
24
    protected function timeToMiliseconds(float $time)
25
    {
26
        return (int)($time * 1000);
27
    }
28
29
    public function executeAfterLastTest(): void
30
    {
31
        $this->sortTestsBySpeed();
32
33
        $this->printResults();
34
    }
35
36
    protected function sortTestsBySpeed(): void
37
    {
38
        arsort($this->tests);
39
    }
40
41
    abstract protected function printResults(): void;
42
43
    protected function testsToPrint(): array
44
    {
45
        return array_slice($this->tests, 0, $this->rows, true);
46
    }
47
48
    protected function getClassName(): string
49
    {
50
        return get_class($this);
51
    }
52
}