CssExpressionTranslator::convertToXpath()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 9.8333
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Xparse\CssExpressionTranslator;
5
6
use Symfony\Component\CssSelector\CssSelectorConverter;
7
use Xparse\ExpressionTranslator\ExpressionTranslatorInterface;
8
9
/**
10
 * @author Ivan Shcherbak <[email protected]>
11
 */
12
class CssExpressionTranslator extends CssSelectorConverter implements ExpressionTranslatorInterface
13
{
14
15 15
    public function convertToXpath(string $expression): string
16
    {
17 15
        $xpathExpression = [];
18 15
        foreach (explode(', ', $expression) as $part) {
19 15
            preg_match('!(.+) (@.+|.+\(\))$!', $part, $matchExpression);
20 15
            if (!array_key_exists(2, $matchExpression)) {
21 7
                $xpathExpression[] = parent::toXPath($part);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (toXPath() instead of convertToXpath()). Are you sure this is correct? If so, you might want to change this to $this->toXPath().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
22
            } else {
23 8
                $xpathExpression[] = parent::toXPath($matchExpression[1]) . '/' . $matchExpression[2];
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (toXPath() instead of convertToXpath()). Are you sure this is correct? If so, you might want to change this to $this->toXPath().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
24
            }
25
        }
26 15
        return implode(' | ', $xpathExpression);
27
    }
28
29
30
}
31