Passed
Push — master ( 462a2e...65d36c )
by Doug
02:19
created

ReportService   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Test Coverage

Coverage 70.97%

Importance

Changes 6
Bugs 0 Features 1
Metric Value
eloc 63
c 6
b 0
f 1
dl 0
loc 90
ccs 44
cts 62
cp 0.7097
rs 10
wmc 12

2 Methods

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

82
                            /** @scrutinizer ignore-type */ sprintf(
Loading history...
83
                                ' and <a href="https://behat.cc">Behat Code Coverage %s</a>',
84
                                InstalledVersions::getPrettyVersion('dvdoug/behat-code-coverage')
85
                            ),
86
                            $colors,
87
                            $thresholds,
88
                            $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

88
                        $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...
89
                        );
90
                    }
91 5
                    $report->process($coverage, $config['target']);
92 5
                    break;
93 20
                case 'php':
94 5
                    $report = new PHP();
95 5
                    $report->process($coverage, $config['target']);
96 5
                    break;
97 15
                case 'text':
98 5
                    $report = new Text(
99 5
                        $config['lowUpperBound'],
100 5
                        $config['highLowerBound'],
101 5
                        $config['showUncoveredFiles'],
102 5
                        $config['showOnlySummary']
103
                    );
104 5
                    echo $report->process($coverage, $config['showColors']);
105 5
                    break;
106 10
                case 'xml':
107 5
                    $report = new XmlFacade('');
108 5
                    $report->process($coverage, $config['target']);
109 5
                    break;
110 5
                case 'cobertura':
111 5
                    $report = new Cobertura();
112 5
                    $report->process($coverage, $config['target']);
113 5
                    break;
114
            }
115
        }
116 8
    }
117
}
118