Listener::clear()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 1
c 2
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php declare(strict_types=1);
2
namespace Behapi\HttpHistory;
3
4
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
5
6
use Behat\Behat\EventDispatcher\Event\ExampleTested;
7
use Behat\Behat\EventDispatcher\Event\ScenarioTested;
8
9
/**
10
 * Starts a new "section" in the HttpHistory object when a scenario-like is
11
 * starting, and clean everything once it's done
12
 *
13
 * @author Baptiste Clavié <[email protected]>
14
 */
15
final class Listener implements EventSubscriberInterface
16
{
17
    /** @var History */
18
    private $history;
19
20
    public function __construct(History $history)
21
    {
22
        $this->history = $history;
23
    }
24
25
    /** {@inheritDoc} */
26
    public static function getSubscribedEvents()
27
    {
28
        return [
29
            ExampleTested::AFTER => ['clear', -99],
30
            ScenarioTested::AFTER => ['clear', -99],
31
        ];
32
    }
33
34
    /** Resets the current history of the current client */
35
    public function clear(): void
36
    {
37
        $this->history->reset();
38
    }
39
}
40