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

CookieMakerExtension::init()   B

Complexity

Conditions 5
Paths 10

Size

Total Lines 26
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 8.439
c 0
b 0
f 0
cc 5
eloc 14
nc 10
nop 2
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