Passed
Pull Request — develop (#8)
by ANTHONIUS
04:10
created

LocalCoverageListener   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 32
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A coverageRefresh() 0 3 1
A coverageStarted() 0 6 1
A getSubscribedEvents() 0 6 1
A coverageCompleted() 0 8 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\Listener;
15
16
use Doyo\Behat\Coverage\Event\CoverageEvent;
17
use spec\Doyo\Behat\Coverage\Listener\AbstractSessionCoverageListener;
18
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
19
20
class LocalCoverageListener extends AbstractSessionCoverageListener implements EventSubscriberInterface
21
{
22 2
    public static function getSubscribedEvents()
23
    {
24
        return [
25 2
            CoverageEvent::REFRESH      => 'coverageRefresh',
26
            CoverageEvent::START        => 'coverageStarted',
27
            CoverageEvent::COMPLETED    => 'coverageCompleted',
28
        ];
29
    }
30
31 1
    public function coverageRefresh()
32
    {
33 1
        $this->session->reset();
34 1
    }
35
36 6
    public function coverageStarted(CoverageEvent $event)
37
    {
38 6
        $session = $this->session;
39
40 6
        $session->setTestCase($event->getTestCase());
41 6
        $session->save();
42 6
    }
43
44 1
    public function coverageCompleted(CoverageEvent $event)
45
    {
46 1
        $session = $this->session;
47 1
        $session->refresh();
48
49 1
        $processor = $this->session->getProcessor();
50 1
        if (null !== $processor) {
51 1
            $event->getProcessor()->merge($processor);
52
        }
53 1
    }
54
}
55