Report::process()   A
last analyzed

Complexity

Conditions 4
Paths 12

Size

Total Lines 29
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 20
c 0
b 0
f 0
dl 0
loc 29
rs 9.6
ccs 18
cts 18
cp 1
cc 4
nc 12
nop 1
crap 4
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 5
    public function __construct($processor, array $options)
24
    {
25 5
        $this->processor = $processor;
26 5
        $this->options = $options;
27
    }
28
29 2
    public static function getSubscribedEvents()
30
    {
31
        return [
32 2
            CoverageEvent::REPORT => 'process'
33
        ];
34
    }
35
36 2
    public function process(CoverageEvent $event)
37
    {
38 2
        $codeCoverage = $event->getProcessor()->getCodeCoverage();
39 2
        $processor = $this->processor;
40 2
        $options = $this->options;
41 2
        $target = $options['target'];
42 2
        $io = $event->getConsoleIO();
43
44 2
        $dir = $target;
45
46 2
        if($options['type'] === 'file'){
47 2
            $dir = dirname($target);
48
        }
49
50 2
        if(!is_dir($dir)){
51 1
            mkdir($dir, 0775, true);
52
        }
53
54
        try{
55 2
            $processor->process($codeCoverage, $target);
56 1
            $io->writeln(sprintf(
57 1
                '<info>Generated code coverage to: <comment>%s</comment></info>',
58
                $target
59
            ));
60 1
        }catch (\Exception $exception){
61 1
            $io->writeln(sprintf(
62 1
                "<info>Failed generate code coverage to <comment>%s</comment>.\n%s</info>",
63
                $target,
64 1
                $exception->getMessage()
65
            ));
66
        }
67
    }
68
69
}