Passed
Push — master ( 5e1705...3969d5 )
by Brian
02:35
created

Attributes   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 4
b 0
f 0
dl 0
loc 20
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A readAttr() 0 7 2
A readAttrText() 0 9 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 readAttrText(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, trans($value));
0 ignored issues
show
Bug introduced by
trans($value) of type Illuminate\Translation\Translator is incompatible with the type string expected by parameter $text of Bmatovu\Ussd\Support\Util::hydrate(). ( Ignorable by Annotation )

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

27
        return Util::hydrate($this->store, /** @scrutinizer ignore-type */ trans($value));
Loading history...
28
    }
29
}
30