Completed
Push — master ( 99f7bd...3359a6 )
by Robbert
02:10
created

xml   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 9
Bugs 4 Features 4
Metric Value
wmc 3
c 9
b 4
f 4
lcom 0
cbo 2
dl 0
loc 53
ccs 25
cts 25
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __callStatic() 0 4 1
A parse() 0 5 1
B css2XPath() 0 38 1
1
<?php
2
3
/*
4
 * This file is part of the Ariadne Component Library.
5
 *
6
 * (c) Muze <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace arc;
13
14
class xml
15
{
16
17 2
    public static function __callStatic( $name, $args )
18
    {
19 2
        return call_user_func_array( [ new xml\Writer(), $name ], $args );
20
    }
21
22 2
    public static function parse( $xml, $encoding = null )
23
    {
24 2
        $parser = new xml\Parser();
25 2
        return $parser->parse( $xml, $encoding );
26
    }
27
28 1
    public static function css2XPath( $cssSelector )
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
29
    {
30
        /* (c) Tijs Verkoyen - http://blog.verkoyen.eu/blog/p/detail/css-selector-to-xpath-query/ */
31
        $cssSelectors = array(
32
            // E F: Matches any F element that is a descendant of an E element
33 1
            '/(\w)\s+(\w)/',
34
            // E > F: Matches any F element that is a child of an element E
35 1
            '/(\w)\s*>\s*(\w)/',
36
            // E:first-child: Matches element E when E is the first child of its parent
37 1
            '/(\w):first-child/',
38
            // E + F: Matches any F element immediately preceded by an element
39 1
            '/(\w)\s*\+\s*(\w)/',
40
            // E[foo]: Matches any E element with the "foo" attribute set (whatever the value)
41 1
            '/(\w)\[([\w\-]+)]/',
42
            // E[foo="warning"]: Matches any E element whose "foo" attribute value is exactly equal to "warning"
43 1
            '/(\w)\[([\w\-]+)\=\"(.*)\"]/',
44
            // div.warning: HTML only. The same as DIV[class~="warning"]
45 1
            '/(\w+|\*)?\.([\w\-]+)+/',
46
            // E#myid: Matches any E element with id-attribute equal to "myid"
47 1
            '/(\w+)+\#([\w\-]+)/',
48
                // #myid: Matches any E element with id-attribute equal to "myid"
49
                '/\#([\w\-]+)/'
50 1
                );
51
52
        $xPathQueries = array(
53 1
            '\1//\2',
54 1
            '\1/\2',
55 1
            '*[1]/self::\1',
56 1
            '\1/following-sibling::*[1]/self::\2',
57 1
            '\1 [ @\2 ]',
58 1
            '\1[ contains( concat( " ", @\2, " " ), concat( " ", "\3", " " ) ) ]',
59 1
            '\1[ contains( concat( " ", @class, " " ), concat( " ", "\2", " " ) ) ]',
60 1
            '\1[ @id = "\2" ]',
61
            '*[ @id = "\1" ]'
62 1
        );
63
64 1
        return (string) '//'. preg_replace($cssSelectors, $xPathQueries, $cssSelector);
65
    }
66
}
67