-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathReportService.php
More file actions
83 lines (63 loc) · 2.06 KB
/
ReportService.php
File metadata and controls
83 lines (63 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* Code Coverage Report Service
*
* @copyright 2013 Anthon Pang
* @license BSD-2-Clause
*/
namespace LeanPHP\Behat\CodeCoverage\Service;
use LeanPHP\Behat\CodeCoverage\Common\Report\Factory;
use SebastianBergmann\CodeCoverage\CodeCoverage;
/**
* Code coverage report service
*
* @author Anthon Pang <apang@softwaredevelopment.ca>
*/
class ReportService
{
/**
* @var array
*/
private $config;
/**
* @var \LeanPHP\Behat\CodeCoverage\Common\Report\Factory
*/
private $factory;
/**
* Constructor
*
* @param array $config
* @param \LeanPHP\Behat\CodeCoverage\Common\Report\Factory $factory
*/
public function __construct(array $config, Factory $factory)
{
$this->config = $config;
$this->factory = $factory;
}
/**
* Generate report
*
* @param CodeCoverage $coverage
*/
public function generateReport(CodeCoverage $coverage)
{
if(!empty($this->config['report']['format']) && !empty($this->config['report']['options'])){
$format = $this->config['report']['format'];
$options = $this->config['report']['options'];
$report = $this->factory->create($format, $options);
$report->process($coverage);
}elseif(!empty($this->config['report']['format']) && !empty($this->config['report']['output'])){
foreach($this->config['report']['format'] AS $format){
if(isset($this->config['report']['output'][$format])){
if(is_array($this->config['report']['output'][$format])) {
$report = $this->factory->create($format, $this->config['report']['output'][$format]);
$report->process($coverage);
}else{
$report = $this->factory->create($format, array('target' => $this->config['report']['output'][$format]));
$report->process($coverage);
}
}
}
}
}
}