Completed
Push — master ( c503a3...9e3cb6 )
by Ivan
02:09
created

BrowserSession   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 2
Metric Value
c 5
b 0
f 2
dl 0
loc 117
wmc 11
lcom 1
cbo 3
ccs 31
cts 31
cp 1
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getBrowser() 0 4 1
A getAlertText() 0 4 1
A confirm() 0 6 1
A removeAllCookies() 0 6 1
A executeJs() 0 4 1
A saveScreenshot() 0 6 1
A hoverNode() 0 6 1
A hover() 0 6 1
A hoverButton() 0 6 1
A hoverField() 0 6 1
1
<?php
2
3
namespace SP\Spiderling;
4
5
use Countable;
6
use SP\Spiderling\Query;
7
8
/**
9
 * @author    Ivan Kerin <[email protected]>
10
 * @copyright 2015, Clippings Ltd.
11
 * @license   http://spdx.org/licenses/BSD-3-Clause
12
 */
13
class BrowserSession extends CrawlerSession
14
{
15
    /**
16
     * @var BrowserInterface
17
     */
18
    private $browser;
19
20
    /**
21
     * @param BrowserInterface $browser
22
     */
23 1
    public function __construct(BrowserInterface $browser) {
24
25 1
        $this->browser = $browser;
26
27 1
        parent::__construct($browser);
28 1
    }
29
30
    /**
31
     * @return BrowserInterface
32
     */
33 1
    public function getBrowser()
34
    {
35 1
        return $this->browser;
36
    }
37
38
    /**
39
     * @return string
40
     */
41 1
    public function getAlertText()
42
    {
43 1
        return $this->browser->getAlertText();
44
    }
45
46
    /**
47
     * @param  string $confirm
48
     */
49 1
    public function confirm($confirm)
50
    {
51 1
        $this->browser->confirm($confirm);
52
53 1
        return $this;
54
    }
55
56
    /**
57
     * @return self
58
     */
59 1
    public function removeAllCookies()
60
    {
61 1
        $this->browser->removeAllCookies();
62
63 1
        return $this;
64
    }
65
66
    /**
67
     * @param  string $javascript
68
     * @return mixed
69
     */
70 1
    public function executeJs($javascript)
71
    {
72 1
        return $this->browser->executeJs($javascript);
73
    }
74
75
    /**
76
     * @param  string $file
77
     * @return self
78
     */
79 1
    public function saveScreenshot($file)
80
    {
81 1
        $this->browser->saveScreenshot($file);
82
83 1
        return $this;
84
    }
85
86
    /**
87
     * @param  Node   $node
88
     * @return self
89
     */
90 1
    public function hoverNode(Node $node)
91
    {
92 1
        $this->browser->moveMouseTo($node->getId());
93
94 1
        return $this;
95
    }
96
97
    /**
98
     * @param  string $selector
99
     * @return self
100
     */
101 1
    public function hover($selector)
102
    {
103 1
        $this->hoverNode($this->get($selector));
104
105 1
        return $this;
106
    }
107
108
    /**
109
     * @param  string $selector
110
     * @return self
111
     */
112 1
    public function hoverButton($selector)
113
    {
114 1
        $this->hoverNode($this->getButton($selector));
115
116 1
        return $this;
117
    }
118
119
    /**
120
     * @param  string $selector
121
     * @return self
122
     */
123 1
    public function hoverField($selector)
124
    {
125 1
        $this->hoverNode($this->getField($selector));
126
127 1
        return $this;
128
    }
129
}
130