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

Report   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Test Coverage

Coverage 81.25%

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 104
ccs 26
cts 32
cp 0.8125
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 20 2
1
<?php
2
3
/*
4
 * This file is part of the doyo/behat-coverage-extension 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 Doyo\Behat\Coverage\Exception\ReportProcessException;
18
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
19
20
class Report implements EventSubscriberInterface
21
{
22
    /**
23
     * @var object
24
     */
25
    private $processor;
26
27
    /**
28
     * @var string
29
     */
30
    private $name;
31
32
    /**
33
     * @var string
34
     */
35
    private $target;
36
37 2
    public static function getSubscribedEvents()
38
    {
39
        return [
40 2
            ReportEvent::PROCESS => 'onReportProcess',
41
        ];
42
    }
43
44
    /**
45
     * @return object
46
     */
47 1
    public function getProcessor()
48
    {
49 1
        return $this->processor;
50
    }
51
52
    /**
53
     * @param object $processor
54
     *
55
     * @return Report
56
     */
57 3
    public function setProcessor($processor)
58
    {
59 3
        $this->processor = $processor;
60
61 3
        return $this;
62
    }
63
64
    /**
65
     * @return string
66
     */
67 1
    public function getName()
68
    {
69 1
        return $this->name;
70
    }
71
72
    /**
73
     * @param string $name
74
     *
75
     * @return Report
76
     */
77 3
    public function setName($name)
78
    {
79 3
        $this->name = $name;
80
81 3
        return $this;
82
    }
83
84
    /**
85
     * @return string
86
     */
87 1
    public function getTarget()
88
    {
89 1
        return $this->target;
90
    }
91
92
    /**
93
     * @param string $target
94
     *
95
     * @return Report
96
     */
97 3
    public function setTarget($target)
98
    {
99 3
        $this->target = $target;
100
101 3
        return $this;
102
    }
103
104 1
    public function onReportProcess(ReportEvent $event)
105
    {
106 1
        $coverage = $event->getCoverage();
107 1
        $io       = $event->getIO();
108
        /* @todo process this error message */
109
        try {
110 1
            $this->processor->process($coverage, $this->target, $this->name);
111 1
            $io->text(
112 1
                sprintf(
113 1
                    '<info><comment>%s</comment> processed to: <comment>%s</comment></info>',
114 1
                    $this->name,
115 1
                    $this->target
116
                ));
117
        } catch (\Exception $e) {
118
            $message = sprintf(
119
                "failed to generate %s report. with Processor message:\n%s",
120
                $this->name,
121
                $e->getMessage()
122
            );
123
            $event->addException(new ReportProcessException($message));
124
        }
125
    }
126
}
127