Passed
Push — master ( 3969d5...0dc1ce )
by Brian
02:40
created

Variables::getVars()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 13
ccs 0
cts 8
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace Bmatovu\Ussd\Traits;
4
5
use Bmatovu\Ussd\Support\Dom;
6
7
trait Variables
8
{
9
    protected function getVar(string $name, string $default = '', string $nodeName = 'variable'): string
10
    {
11
        $children = Dom::getElements($this->node->childNodes, $nodeName);
12
13
        foreach ($children as $child) {
14
            if ($name == $this->readAttrText('name', '', $child))
0 ignored issues
show
Bug introduced by
It seems like readAttrText() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

14
            if ($name == $this->/** @scrutinizer ignore-call */ readAttrText('name', '', $child))
Loading history...
15
                return $this->readAttrText('value', $default, $child);
16
        }
17
18
        return $default;
19
    }
20
21
    protected function getVars(string $nodeName = 'variable'): array
22
    {
23
        $children = Dom::getElements($this->node->childNodes, $nodeName);
24
25
        $variables = [];
26
        foreach ($children as $child) {
27
            $name = $this->readAttrText('name', '', $child);
28
            $value = $this->readAttrText('value', '', $child);
29
30
            $variables[$name] = $value;
31
        }
32
33
        return $variables;
34
    }
35
}
36