GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

VCRSubscriber   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 15
c 1
b 0
f 0
lcom 1
cbo 6
dl 0
loc 99
ccs 0
cts 56
cp 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getSubscribedEvents() 0 11 1
A turnOnVCR() 0 9 2
A captureOutlineOnBeforeOutlineEvent() 0 8 2
A forgetOutlineOnAfterOutlineEvent() 0 8 2
B configureVCR() 0 27 6
A turnOffVCR() 0 4 1
1
<?php
2
3
namespace BVCR\Behat\EventDispatcher;
4
5
use Behat\Behat\EventDispatcher\Event\BeforeOutlineTested;
6
use Behat\Behat\EventDispatcher\Event\ExampleTested;
7
use Behat\Behat\EventDispatcher\Event\OutlineTested;
8
use Behat\Gherkin\Node\OutlineNode;
9
use Symfony\Component\EventDispatcher\Event;
10
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11
use Behat\Behat\EventDispatcher\Event\ScenarioTested;
12
use VCR\Videorecorder;
13
use BVCR\Behat\Resolver\ConfigurationResolver;
14
use BVCR\Behat\Resolver\Configuration;
15
16
class VCRSubscriber implements EventSubscriberInterface
17
{
18
    /** @var \VCR\Videorecorder */
19
    private $videorecorder;
20
    /** @var \BVCR\Behat\Resolver\ConfigurationResolver */
21
    private $configurationResolver;
22
    /** @var OutlineNode */
23
    private $outline;
24
25
26
    public function __construct(Videorecorder $videorecorder, ConfigurationResolver $configurationResolver)
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $configurationResolver exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
27
    {
28
        $this->videorecorder = $videorecorder;
29
        $this->configurationResolver = $configurationResolver;
30
    }
31
32
    public static function getSubscribedEvents()
33
    {
34
        return array(
35
            ScenarioTested::BEFORE => 'turnOnVCR',
36
            ScenarioTested::AFTER => 'turnOffVCR',
37
            ExampleTested::BEFORE => 'turnOnVCR',
38
            ExampleTested::AFTER => 'turnOffVCR',
39
            OutlineTested::BEFORE => 'captureOutlineOnBeforeOutlineEvent',
40
            OutlineTested::AFTER => 'forgetOutlineOnAfterOutlineEvent',
41
        );
42
    }
43
44
    public function turnOnVCR(ScenarioTested $event)
45
    {
46
        $configuration = $this->configurationResolver->resolve($event->getScenario());
47
48
        if ($configuration) {
49
            $this->videorecorder->turnOn();
50
            $this->configureVCR($configuration, $event);
51
        }
52
    }
53
54
    /**
55
     * Captures outline into the ivar on outline BEFORE event.
56
     *
57
     * @param Event $event
58
     */
59
    public function captureOutlineOnBeforeOutlineEvent(Event $event)
60
    {
61
        if (!$event instanceof BeforeOutlineTested) {
62
            return;
63
        }
64
65
        $this->outline = $event->getOutline();
66
    }
67
68
    /**
69
     * Removes outline from the ivar on outline AFTER event.
70
     *
71
     * @param Event $event
72
     */
73
    public function forgetOutlineOnAfterOutlineEvent(Event $event)
74
    {
75
        if (!$event instanceof BeforeOutlineTested) {
76
            return;
77
        }
78
79
        $this->outline = null;
80
    }
81
82
    private function configureVCR(Configuration $configuration, ScenarioTested $event)
83
    {
84
        $currentVcrConfiguration = $this->videorecorder->configure();
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $currentVcrConfiguration exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
85
86
        if ($configuration->getCassettePath()) {
87
            $currentVcrConfiguration->setCassettePath($configuration->getCassettePath());
88
        }
89
        if ($configuration->getCassetteStorage()) {
90
            $currentVcrConfiguration->setStorage($configuration->getCassetteStorage());
91
        }
92
        if ($configuration->getLibraryHooks()) {
93
            $currentVcrConfiguration->enableLibraryHooks($configuration->getLibraryHooks());
94
        }
95
        if ($configuration->getRequestMatchers()) {
96
            $currentVcrConfiguration->enableRequestMatchers($configuration->getRequestMatchers());
97
        }
98
        if ($configuration->getMode()) {
99
            $currentVcrConfiguration->setMode($configuration->getMode());
100
        }
101
102
        $filename = $configuration->getFileNamingStrategy()->createFilename(
103
            $event->getFeature(),
104
            $event->getScenario(),
105
            $this->outline
106
        );
107
        $this->videorecorder->insertCassette($filename);
108
    }
109
110
    public function turnOffVCR()
111
    {
112
        $this->videorecorder->turnOff();
113
    }
114
}
115