Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
CoverageSummary
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
5 / 5
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 executedLines
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 executableLines
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 percentage
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 percentageAsString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/**
6 * Fast Forward Development Tools for PHP projects.
7 *
8 * This file is part of fast-forward/dev-tools project.
9 *
10 * @author   Felipe SayĆ£o Lobato Abreu <github@mentordosnerds.com>
11 * @license  https://opensource.org/licenses/MIT MIT License
12 *
13 * @see      https://github.com/php-fast-forward/
14 * @see      https://github.com/php-fast-forward/dev-tools
15 * @see      https://github.com/php-fast-forward/dev-tools/issues
16 * @see      https://php-fast-forward.github.io/dev-tools/
17 * @see      https://datatracker.ietf.org/doc/html/rfc2119
18 */
19
20namespace FastForward\DevTools\PhpUnit\Coverage;
21
22/**
23 * Represents the line coverage summary extracted from a PHPUnit `coverage-php` report.
24 */
25  class CoverageSummary
26{
27    /**
28     * Initializes a new instance of the CoverageSummary class.
29     *
30     * @param int $executedLines Number of executable lines covered
31     * @param int $executableLines Total executable lines in the analyzed code
32     */
33    public function __construct(
34        private int $executedLines,
35        private int $executableLines,
36    ) {}
37
38    /**
39     * Returns the number of executable lines that were executed.
40     *
41     * @return int
42     */
43    public function executedLines(): int
44    {
45        return $this->executedLines;
46    }
47
48    /**
49     * Returns the total number of executable lines.
50     *
51     * @return int
52     */
53    public function executableLines(): int
54    {
55        return $this->executableLines;
56    }
57
58    /**
59     * Returns the executed line coverage as a percentage.
60     *
61     * @return float
62     */
63    public function percentage(): float
64    {
65        if (0 === $this->executableLines) {
66            return 100.0;
67        }
68
69        return ($this->executedLines / $this->executableLines) * 100;
70    }
71
72    /**
73     * Returns the executed line coverage as a formatted percentage string.
74     *
75     * @return string
76     */
77    public function percentageAsString(): string
78    {
79        return \sprintf('%01.2F%%', $this->percentage());
80    }
81}