Completed
Push — master ( cce6a6...8438be )
by Ivan
03:16
created

Submit   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

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 19
cts 19
cp 1
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 1
    public function getForm()
18
    {
19 1
        return $this->getChildren('./ancestor::form')->item(0);
20
    }
21
22
    /**
23
     * @return Form
24
     */
25 1
    public function getFormElement()
26
    {
27 1
        if (null === $this->form) {
28 1
            $this->form = new Form($this->getReader(), $this->getForm());
0 ignored issues
show
Compatibility introduced by
$this->getForm() of type object<DOMNode> is not a sub-type of object<DOMElement>. It seems like you assume a child class of the class DOMNode to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
29 1
        }
30
31 1
        return $this->form;
32
    }
33
34 1
    public function getDefaultData()
35
    {
36 1
        $data = [];
37
38 1
        if ($this->getAttribute('name')) {
39 1
            $data[$this->getAttribute('name')] = $this->getAttribute('value');
40 1
        }
41
42 1
        return $data;
43
    }
44
45
    /**
46
     * @return Request
47
     */
48 1
    public function clickRequest()
49
    {
50 1
        $data = [];
51
52 1
        if ($this->getAttribute('name')) {
53 1
            $data[$this->getAttribute('name')] = $this->getAttribute('value');
54 1
        }
55
56 1
        return $this->getFormElement()->getRequest($data);
57
    }
58
}
59