SimpleXmlElement::find()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2.032
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rs\XmlFilter\Document;
6
7
use Rs\XmlFilter\Exception\EvaluationException;
8
9
class SimpleXmlElement extends \SimpleXMLElement implements Element
10
{
11 37
    public function find(string $path) : array
12
    {
13 37
        $result = $this->xpath($path);
14
15 37
        if (false === $result) {
16
            throw new EvaluationException(sprintf('unable to evaluate the "%s"', $path), $this, ['path' => $path]);
17
        }
18
19 37
        return $result;
20
    }
21
22 1
    public function attribute($name) : string
23
    {
24 1
        foreach ($this->attributes() as $key => $value) {
25 1
            if ($key === $name) {
26 1
                return (string) $value;
27
            }
28
        }
29
30 1
        return '';
31
    }
32
}
33