Completed
Push — master ( 0a1211...3741d7 )
by Nils
02:20
created

CookieMakerExtension   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B init() 0 26 5
A addSessions() 0 4 1
1
<?php
2
3
namespace whm\Smoke\Extensions\CookieMaker;
4
5
use Koalamon\CookieMakerHelper\CookieMaker;
6
use whm\Smoke\Http\Session;
7
use whm\Smoke\Scanner\SessionContainer;
8
9
class CookieMakerExtension
10
{
11
    private $executable = 'CookieMaker';
12
13
    private $sessionContainer;
14
15
    public function init(array $sessions, $executable = null)
16
    {
17
        if ($executable) {
18
            $this->executable = $executable;
19
        }
20
21
        $this->sessionContainer = new SessionContainer();
22
23
        foreach ($sessions as $sessionName => $session) {
24
25
            try {
26
                $cookieMaker = new CookieMaker($this->executable);
27
                $cookies = $cookieMaker->getCookies($session);
28
            } catch (\Exception $e) {
29
                die('FALLBACK');
0 ignored issues
show
Coding Style Compatibility introduced by
The method init() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
30
            }
31
32
            $session = new Session();
33
34
            foreach ($cookies as $key => $value) {
35
                $session->addCookie($key, $value);
36
            }
37
38
            $this->sessionContainer->addSession($sessionName, $session);
39
        }
40
    }
41
42
    /**
43
     * @Event("ResponseRetriever.setSessionContainer.before")
44
     */
45
    public function addSessions(SessionContainer $sessionContainer)
46
    {
47
        $sessionContainer->addContainer($this->sessionContainer);
48
    }
49
}
50