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

Attributes   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
c 3
b 0
f 0
dl 0
loc 31
ccs 14
cts 14
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A readAttrText() 0 9 2
A readAttrHydrate() 0 9 2
A readAttr() 0 7 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