Passed
Pull Request — develop (#4)
by ANTHONIUS
05:04
created

LocalCoverage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 36
ccs 13
cts 15
cp 0.8667
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A onCoverageRefresh() 0 3 1
A __construct() 0 4 1
A onCoverageStarted() 0 3 1
A onCoverageStopped() 0 7 1
A getSubscribedEvents() 0 6 1
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\CoverageEvent;
17
use SebastianBergmann\CodeCoverage\CodeCoverage;
18
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
19
20
class LocalCoverage implements EventSubscriberInterface
21
{
22
    private $coverage;
23
24 6
    public function __construct(
25
        CodeCoverage $coverage
26
    ) {
27 6
        $this->coverage = $coverage;
28
    }
29
30 2
    public static function getSubscribedEvents()
31
    {
32
        return [
33 2
            CoverageEvent::START   => 'onCoverageStarted',
34 1
            CoverageEvent::STOP    => ['onCoverageStopped', 1000],
35 1
            CoverageEvent::REFRESH => 'onCoverageRefresh',
36
        ];
37
    }
38
39 2
    public function onCoverageStarted(CoverageEvent $event)
40
    {
41 2
        $this->coverage->start($event->getCoverageId());
42
    }
43
44 1
    public function onCoverageStopped(CoverageEvent $event)
45
    {
46 1
        $coverage = $this->coverage;
47
48 1
        $coverage->stop();
49 1
        $data = $coverage->getData(true);
50 1
        $event->updateCoverage($data);
51
    }
52
53
    public function onCoverageRefresh()
54
    {
55
        $this->coverage->clear();
56
    }
57
}
58