Passed
Push — dependabot/pip/docs/sphinx-app... ( 77c07a )
by
unknown
03:13
created

ReportService   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Test Coverage

Coverage 55.42%

Importance

Changes 7
Bugs 0 Features 1
Metric Value
eloc 73
c 7
b 0
f 1
dl 0
loc 103
ccs 46
cts 83
cp 0.5542
rs 10
wmc 13

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
C generateReport() 0 85 12
1
<?php
2
/**
3
 * Behat Code Coverage
4
 */
5
declare(strict_types=1);
6
7
namespace DVDoug\Behat\CodeCoverage\Service;
8
9
use Composer\InstalledVersions;
10
use Composer\Semver\VersionParser;
11
use SebastianBergmann\CodeCoverage\CodeCoverage;
12
use SebastianBergmann\CodeCoverage\Report\Clover;
13
use SebastianBergmann\CodeCoverage\Report\Cobertura;
14
use SebastianBergmann\CodeCoverage\Report\Crap4j;
15
use SebastianBergmann\CodeCoverage\Report\Html\Colors;
0 ignored issues
show
Bug introduced by
The type SebastianBergmann\CodeCoverage\Report\Html\Colors was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use SebastianBergmann\CodeCoverage\Report\Html\CustomCssFile;
0 ignored issues
show
Bug introduced by
The type SebastianBergmann\CodeCo...port\Html\CustomCssFile was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use SebastianBergmann\CodeCoverage\Report\Html\Facade as HtmlFacade;
18
use SebastianBergmann\CodeCoverage\Report\PHP;
19
use SebastianBergmann\CodeCoverage\Report\Text;
20
use SebastianBergmann\CodeCoverage\Report\Thresholds;
0 ignored issues
show
Bug introduced by
The type SebastianBergmann\CodeCoverage\Report\Thresholds was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use SebastianBergmann\CodeCoverage\Report\Xml\Facade as XmlFacade;
22
23
use function sprintf;
24
25
class ReportService
26
{
27
    /**
28
     * @var array
29
     */
30
    private $config;
31
32
    /**
33
     * Constructor.
34
     */
35 52
    public function __construct(array $reportConfig)
36
    {
37 52
        $this->config = $reportConfig;
38
    }
39
40
    /**
41
     * Generate report.
42
     */
43 32
    public function generateReport(CodeCoverage $coverage): void
44
    {
45 32
        foreach ($this->config as $format => $config) {
46
            switch ($format) {
47 32
                case 'clover':
48 8
                    $report = new Clover();
49 8
                    $report->process($coverage, $config['target'], $config['name']);
50 8
                    break;
51 28
                case 'crap4j':
52 8
                    $report = new Crap4j();
53 8
                    $report->process($coverage, $config['target'], $config['name']);
54 8
                    break;
55 20
                case 'html':
56 4
                    if (InstalledVersions::satisfies(new VersionParser(), 'phpunit/php-code-coverage', '^9.0')) {
57 4
                        $report = new HtmlFacade(
58 4
                            $config['lowUpperBound'],
59 4
                            $config['highLowerBound'],
60 4
                            sprintf(
61 3
                                ' and <a href="https://behat.cc">Behat Code Coverage %s</a>',
62 4
                                InstalledVersions::getPrettyVersion('dvdoug/behat-code-coverage')
63 3
                            )
64 3
                        );
65
                    } else {
66
                        $thresholds = Thresholds::from(
67
                            $config['lowUpperBound'],
68
                            $config['highLowerBound'],
69
                        );
70
                        $colors = Colors::from(
71
                            $config['colors']['successLow'],
72
                            $config['colors']['successMedium'],
73
                            $config['colors']['successHigh'],
74
                            $config['colors']['warning'],
75
                            $config['colors']['danger'],
76
                        );
77
                        if ($config['customCSSFile']) {
78
                            $customCss = CustomCssFile::from($config['customCSSFile']);
79
                        } else {
80
                            $customCss = CustomCssFile::default();
81
                        }
82
                        $report = new HtmlFacade(
83
                            sprintf(
0 ignored issues
show
Bug introduced by
sprintf(' and <a href="h.../behat-code-coverage')) of type string is incompatible with the type integer expected by parameter $lowUpperBound of SebastianBergmann\CodeCo...l\Facade::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

83
                            /** @scrutinizer ignore-type */ sprintf(
Loading history...
84
                                ' and <a href="https://behat.cc">Behat Code Coverage %s</a>',
85
                                InstalledVersions::getPrettyVersion('dvdoug/behat-code-coverage')
86
                            ),
87
                            $colors,
88
                            $thresholds,
89
                            $customCss
0 ignored issues
show
Unused Code introduced by
The call to SebastianBergmann\CodeCo...l\Facade::__construct() has too many arguments starting with $customCss. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

89
                        $report = /** @scrutinizer ignore-call */ new HtmlFacade(

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
90
                        );
91
                    }
92 4
                    $report->process($coverage, $config['target']);
93 4
                    break;
94 16
                case 'php':
95 4
                    $report = new PHP();
96 4
                    $report->process($coverage, $config['target']);
97 4
                    break;
98 12
                case 'text':
99 4
                    if (InstalledVersions::satisfies(new VersionParser(), 'phpunit/php-code-coverage', '^9.0')) {
100 4
                        $report = new Text(
101 4
                            $config['lowUpperBound'],
102 4
                            $config['highLowerBound'],
103 4
                            $config['showUncoveredFiles'],
104 4
                            $config['showOnlySummary']
105 3
                        );
106 4
                        echo $report->process($coverage, $config['showColors']);
107
                    } else {
108
                        $thresholds = Thresholds::from(
109
                            $config['lowUpperBound'],
110
                            $config['highLowerBound'],
111
                        );
112
                        $report = new Text(
113
                            $thresholds,
114
                            $config['showUncoveredFiles'],
115
                            $config['showOnlySummary']
116
                        );
117
                        echo $report->process($coverage, $config['showColors']);
118
                    }
119 4
                    break;
120 8
                case 'xml':
121 4
                    $report = new XmlFacade('');
122 4
                    $report->process($coverage, $config['target']);
123 4
                    break;
124 4
                case 'cobertura':
125 4
                    $report = new Cobertura();
126 4
                    $report->process($coverage, $config['target']);
127 4
                    break;
128
            }
129
        }
130
    }
131
}
132