Selector   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isCSS() 0 9 2
A isXPath() 0 7 1
1
<?php
2
namespace Zrashwani\NewsScrapper;
3
4
use Symfony\Component\CssSelector\CssSelector;
5
use Symfony\Component\CssSelector\Exception\ParseException;
6
7
/**
8
 * Set of useful functions for using CSS and XPath selector.
9
 * inspired from CodeCeption locator
10
 */
11
class Selector
12
{
13
    
14
    /**
15
     * @param $selector
16
     * @return bool
17
     */
18
    public static function isCSS($selector)
19
    {
20
        try {
21
            CssSelector::toXPath($selector);
22
        } catch (ParseException $e) {
23
            return false;
24
        }
25
        return true;
26
    }
27
    
28
29
    /**
30
     * Checks that locator is an XPath
31
     *
32
     * @param $selector
33
     * @return bool
34
     */
35
    public static function isXPath($selector)
36
    {
37
        libxml_use_internal_errors(true);
38
        $document = new \DOMDocument('1.0', 'UTF-8');
39
        $xpath = new \DOMXPath($document);
40
        return $xpath->evaluate($selector, $document) !== false;
41
    }
42
}
43