Radio::click()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 7
cts 7
cp 1
rs 9.6667
cc 2
eloc 6
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 Radio extends Checkbox
11
{
12
    const CHECKED = "//input[@type='radio' and @name='%s' and @checked]";
13
14 1
    public function uncheckOthers()
15
    {
16 1
        $xpath = sprintf(Radio::CHECKED, $this->getName());
17
18 1
        foreach ($this->getReader()->query($xpath) as $radio) {
19 1
            $radio->removeAttribute('checked');
20 1
        }
21 1
    }
22
23 1
    public function click()
24
    {
25 1
        if ($this->hasAttribute('checked')) {
26 1
            $this->removeAttribute('checked');
27 1
        } else {
28 1
            $this->uncheckOthers();
29 1
            $this->setAttribute('checked', 'checked');
30
        }
31 1
    }
32
}
33