Passed
Push — master ( b64ee5...4e7602 )
by Jakub
01:54
created

PercentFormatter::render()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
c 1
b 0
f 1
dl 0
loc 16
ccs 12
cts 12
cp 1
rs 9.9
cc 4
nc 4
nop 1
crap 4
1
<?php
2
declare(strict_types=1);
3
4
namespace MyTester\CodeCoverage;
5
6
/**
7
 * Percent formatter for code coverage
8
 * Reports only total % of code coverage
9
 *
10
 * @author Jakub Konečný
11
 * @internal
12
 */
13
final class PercentFormatter implements \MyTester\ICodeCoverageFormatter
14
{
15 1
    public function render(array $data): string
16
    {
17 1
        $result = "Calculating code coverage... ";
18 1
        $totalLines = 0;
19 1
        $coveredLines = 0;
20 1
        foreach ($data as $file) {
21 1
            foreach ($file as $line) {
22 1
                $totalLines++;
23 1
                if ($line > 0) {
24 1
                    $coveredLines++;
25
                }
26
            }
27
        }
28 1
        $coveragePercent = (int) (($coveredLines / $totalLines) * 100);
29 1
        $result .= $coveragePercent . "% covered\n";
30 1
        return $result;
31
    }
32
}
33