Passed
Push — develop ( a4c97f...02f249 )
by ANTHONIUS
04:04
created

Report   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
eloc 27
c 0
b 0
f 0
dl 0
loc 54
rs 10
ccs 0
cts 23
cp 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 4 1
A process() 0 29 4
A __construct() 0 4 1
1
<?php
2
3
4
namespace Doyo\PhpSpec\CodeCoverage;
5
6
7
use Doyo\PhpSpec\CodeCoverage\Event\CoverageEvent;
8
use SebastianBergmann\CodeCoverage\CodeCoverage;
9
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10
11
class Report implements EventSubscriberInterface
12
{
13
    /**
14
     * @var mixed
15
     */
16
    private $processor;
17
18
    /**
19
     * @var array
20
     */
21
    private $options;
22
23
    public function __construct($processor, array $options)
24
    {
25
        $this->processor = $processor;
26
        $this->options = $options;
27
    }
28
29
    public static function getSubscribedEvents()
30
    {
31
        return [
32
            CoverageEvent::REPORT => 'process'
33
        ];
34
    }
35
36
    public function process(CoverageEvent $event)
37
    {
38
        $codeCoverage = $event->getProcessor()->getCodeCoverage();
39
        $processor = $this->processor;
40
        $options = $this->options;
41
        $target = $options['target'];
42
        $io = $event->getConsoleIO();
43
44
        $dir = $target;
45
46
        if($options['type'] === 'file'){
47
            $dir = dirname($target);
48
        }
49
50
        if(!is_dir($dir)){
51
            mkdir($dir, 0775, true);
52
        }
53
54
        try{
55
            $processor->process($codeCoverage, $target);
56
            $io->writeln(sprintf(
57
                '<info>Generated code coverage to: <comment>%s</comment></info>',
58
                $target
59
            ));
60
        }catch (\Exception $exception){
61
            $io->writeln(sprintf(
62
                "<info>Failed generate code coverage to <comment>%s</comment>.\n%s</info>",
63
                $target,
64
                $exception->getMessage()
65
            ));
66
        }
67
    }
68
69
}