Passed
Pull Request — develop (#5)
by ANTHONIUS
04:07
created

Report   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 99
ccs 26
cts 28
cp 0.9286
rs 10
c 0
b 0
f 0
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A getTarget() 0 3 1
A setTarget() 0 5 1
A getSubscribedEvents() 0 4 1
A getProcessor() 0 3 1
A setName() 0 5 1
A setProcessor() 0 5 1
A onReportProcess() 0 15 2
1
<?php
2
3
/*
4
 * This file is part of the DoyoUserBundle project.
5
 *
6
 * (c) Anthonius Munthi <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Doyo\Behat\Coverage\Bridge;
15
16
use Doyo\Behat\Coverage\Event\ReportEvent;
17
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
18
19
class Report implements EventSubscriberInterface
20
{
21
    /**
22
     * @var object
23
     */
24
    private $processor;
25
26
    /**
27
     * @var string
28
     */
29
    private $name;
30
31
    /**
32
     * @var string
33
     */
34
    private $target;
35
36 2
    public static function getSubscribedEvents()
37
    {
38
        return [
39 2
            ReportEvent::PROCESS => 'onReportProcess',
40
        ];
41
    }
42
43
    /**
44
     * @return object
45
     */
46 1
    public function getProcessor()
47
    {
48 1
        return $this->processor;
49
    }
50
51
    /**
52
     * @param object $processor
53
     *
54
     * @return Report
55
     */
56 3
    public function setProcessor($processor)
57
    {
58 3
        $this->processor = $processor;
59
60 3
        return $this;
61
    }
62
63
    /**
64
     * @return string
65
     */
66 1
    public function getName()
67
    {
68 1
        return $this->name;
69
    }
70
71
    /**
72
     * @param string $name
73
     *
74
     * @return Report
75
     */
76 3
    public function setName($name)
77
    {
78 3
        $this->name = $name;
79
80 3
        return $this;
81
    }
82
83
    /**
84
     * @return string
85
     */
86 1
    public function getTarget()
87
    {
88 1
        return $this->target;
89
    }
90
91
    /**
92
     * @param string $target
93
     *
94
     * @return Report
95
     */
96 3
    public function setTarget($target)
97
    {
98 3
        $this->target = $target;
99
100 3
        return $this;
101
    }
102
103 1
    public function onReportProcess(ReportEvent $event)
104
    {
105 1
        $coverage = $event->getCoverage();
106 1
        $io       = $event->getIO();
107
        /* @todo process this error message */
108
        try {
109 1
            $this->processor->process($coverage, $this->target, $this->name);
110 1
            $io->text(
111 1
                sprintf(
112 1
                    '<info>Generated <comment>%s</comment> to <comment>%s</comment></info>',
113 1
                    $this->name,
114 1
                    $this->target
115
                ));
116
        } catch (\Exception $e) {
117
            $io->error('Failed to generate '.$this->name.' report.');
118
        }
119
    }
120
}
121