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

LocalCoverage::onCoverageStarted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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