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

Submit   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 7
c 2
b 0
f 1
lcom 1
cbo 2
dl 0
loc 49
ccs 0
cts 16
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getForm() 0 4 1
A getFormElement() 0 8 2
A getDefaultData() 0 10 2
A clickRequest() 0 10 2
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