AbstractXPath   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 40%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 1
c 3
b 0
f 1
lcom 1
cbo 1
dl 0
loc 69
ccs 2
cts 5
cp 0.4
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
getType() 0 1 ?
getMatchers() 0 1 ?
A getXPath() 0 8 1
1
<?php
2
3
namespace SP\Spiderling\Query;
4
5
/**
6
 * @author    Ivan Kerin <[email protected]>
7
 * @copyright 2015, Clippings Ltd.
8
 * @license   http://spdx.org/licenses/BSD-3-Clause
9
 */
10
abstract class AbstractXPath extends AbstractQuery
11
{
12
    /**
13
     * Match by id
14
     */
15
    const ID = "@id = '%s'";
16
17
    /**
18
     * Match by name
19
     */
20
    const NAME = "@name = '%s'";
21
22
    /**
23
     * Match by placeholder
24
     */
25
    const PLACEHOLDER = "@placeholder = '%s'";
26
27
    /**
28
     * Match by label pointing to element
29
     */
30
    const LABEL_FOR = "@id = //label[normalize-space() = '%s']/@for";
31
32
    /**
33
     * Match by text of an option tag inside the select
34
     */
35
    const OPTION_TEXT = "(self::select and ./option[(@value = \"\" or not(@value)) and contains(normalize-space(), \"%s\")])";
36
37
    /**
38
     * Match by title
39
     */
40
    const TITLE = "contains(@title, '%s')";
41
42
    /**
43
     * Match by plain text content
44
     */
45
    const TEXT = "contains(normalize-space(), '%s')";
46
47
    /**
48
     * Match by alt of an img tag
49
     */
50
    const IMG_ALT = "descendant::img[contains(@alt, '%s')]";
51
52
    /**
53
     * Match by value of element
54
     */
55
    const VALUE = "contains(@value, '%s')";
56
57
    /**
58
     * @return string
59
     */
60 1
    public function getXPath()
61
    {
62
        $type = $this->getType();
63
        $combined = join(' or ', $this->getMatchers());
64
        $filled = str_replace('%s', $this->getSelector(), $combined);
65
66 1
        return "//*[($type) and ($filled)]";
67
    }
68
69
    /**
70
     * @return string
71
     */
72
    abstract public function getType();
73
74
    /**
75
     * @return array
76
     */
77
    abstract public function getMatchers();
78
}
79