Completed
Push — master ( c9bbeb...1f0ecb )
by Ivan
03:21
created

Submit::getFormElement()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 9.4286
cc 2
eloc 4
nc 2
nop 0
crap 6
1
<?php
2
3
namespace SP\Crawler\Element;
4
5
/**
6
 * @author    Ivan Kerin <[email protected]>
7
 * @copyright 2015, Clippings Ltd.
8
 * @license   http://spdx.org/licenses/BSD-3-Clause
9
 */
10
class Submit extends AbstractElement implements ClickRequestInterface
11
{
12
    private $form;
13
14
    /**
15
     * @return DOMElement
16
     */
17
    public function getForm()
18
    {
19
        return $this->getChildren('./ancestor::form')->item(0);
20
    }
21
22
    /**
23
     * @return Form
24
     */
25
    public function getFormElement()
26
    {
27
        if (null === $this->form) {
28
            $this->form = new Form($this->getReader(), $this->getForm());
29
        }
30
31
        return $this->form;
32
    }
33
34
    public function getDefaultData()
35
    {
36
        $data = [];
37
38
        if ($this->getAttribute('name')) {
39
            $data[$this->getAttribute('name')] = $this->getAttribute('value');
40
        }
41
42
        return $data;
43
    }
44
45
    /**
46
     * @return Request
47
     */
48
    public function clickRequest()
49
    {
50
        $data = [];
51
52
        if ($this->getAttribute('name')) {
53
            $data[$this->getAttribute('name')] = $this->getAttribute('value');
54
        }
55
56
        return $this->getFormElement()->getRequest($data);
57
    }
58
}
59