Passed
Pull Request — master (#14)
by
unknown
05:09 queued 03:14
created

ReportService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 1
c 2
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
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 65
    public function __construct(array $reportConfig)
36
    {
37 65
        $this->config = $reportConfig;
38
    }
39
40
    /**
41
     * Generate report.
42
     */
43 40
    public function generateReport(CodeCoverage $coverage): void
44
    {
45 40
        foreach ($this->config as $format => $config) {
46 16
            switch ($format) {
47 40
                case 'clover':
48 10
                    $report = new Clover();
49 10
                    $report->process($coverage, $config['target'], $config['name']);
50 10
                    break;
51 35
                case 'crap4j':
52 10
                    $report = new Crap4j();
53 10
                    $report->process($coverage, $config['target'], $config['name']);
54 10
                    break;
55 25
                case 'html':
56 5
                    if (InstalledVersions::satisfies(new VersionParser(), 'phpunit/php-code-coverage', '^9.0')) {
57 5
                        $report = new HtmlFacade(
58 5
                            $config['lowUpperBound'],
59 5
                            $config['highLowerBound'],
60 5
                            sprintf(
61 3
                                ' and <a href="https://behat.cc">Behat Code Coverage %s</a>',
62 5
                                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 5
                    $report->process($coverage, $config['target']);
93 5
                    break;
94 20
                case 'php':
95 5
                    $report = new PHP();
96 5
                    $report->process($coverage, $config['target']);
97 5
                    break;
98 15
                case 'text':
99 5
                    if (InstalledVersions::satisfies(new VersionParser(), 'phpunit/php-code-coverage', '^9.0')) {
100 5
                        $report = new Text(
101 5
                            $config['lowUpperBound'],
102 5
                            $config['highLowerBound'],
103 5
                            $config['showUncoveredFiles'],
104 5
                            $config['showOnlySummary']
105 3
                        );
106 5
                        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 5
                    break;
120 10
                case 'xml':
121 5
                    $report = new XmlFacade('');
122 5
                    $report->process($coverage, $config['target']);
123 5
                    break;
124 5
                case 'cobertura':
125 5
                    $report = new Cobertura();
126 5
                    $report->process($coverage, $config['target']);
127 5
                    break;
128
            }
129
        }
130
    }
131
}
132