Submit::getDefaultData()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4286
cc 2
eloc 5
nc 2
nop 0
crap 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