Passed
Push — master ( 057162...5e1705 )
by Brian
02:41
created

Attributes::readAttrHydrate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 3
crap 2
1
<?php
2
3
namespace Bmatovu\Ussd\Traits;
4
5
use Bmatovu\Ussd\Support\Util;
6
use DOMNode;
7
8
trait Attributes
9
{
10 27
    public function readAttr(string $name, $default = '', DOMNode $node = null)
11
    {
12 27
        if (!$node) {
13 27
            return $this->node->attributes->getNamedItem($name)->nodeValue ?? $default;
14
        }
15
16 2
        return $node->attributes->getNamedItem($name)->nodeValue ?? $default;
0 ignored issues
show
Bug introduced by
The method getNamedItem() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

16
        return $node->attributes->/** @scrutinizer ignore-call */ getNamedItem($name)->nodeValue ?? $default;

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
17
    }
18
19 15
    public function readAttrHydrate(string $name = 'text', $default = '', DOMNode $node = null)
20
    {
21 15
        $value = $this->readAttr($name, $default, $node);
22
23 15
        if (!$value) {
24 2
            return $value;
25
        }
26
27 14
        return Util::hydrate($this->store, $value);
28
    }
29
30 15
    public function readAttrText(string $name = 'text', $default = '', DOMNode $node = null)
31
    {
32 15
        $value = $this->readAttrHydrate($name, $default, $node);
33
34 15
        if (!$value) {
35 2
            return $value;
36
        }
37
38 14
        return trans($value);
39
    }
40
}
41