Coverspector   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getUncovered() 0 5 1
A getCoverage() 0 11 2
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Coverspector;
6
7
class Coverspector
8
{
9
    private $report;
10
11
    public function __construct(string $report)
12
    {
13
        $this->report = $report;
14
    }
15
16
    public function getCoverage(): float
17
    {
18
        $regexp = '/(Classes|Methods|Lines)\:\s+[\d]+\.[\d]+%\s+\(([\d]+)\/([\d]+)\)/m';
19
        preg_match_all($regexp, $this->report, $matches);
20
21
        $totals = 0;
22
        foreach ($matches[2] as $index => $metrics) {
23
            $totals += $metrics / $matches[3][$index];
24
        }
25
26
        return $totals / count($matches[2]) * 100;
27
    }
28
29
    public function getUncovered(): array
30
    {
31
        $regexp = '/.*\n.*Methods:.*Lines:\s*\d{1,2}\.\d+\%.*/';
32
        preg_match_all($regexp, $this->report, $matches);
33
        return $matches[0];
34
    }
35
}
36