Issues (33)

src/Traits/Variables.php (1 issue)

Labels
Severity
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
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
19
        return $default;
20
    }
21
22
    protected function getVars(string $nodeName = 'variable'): array
23
    {
24
        $children = Dom::getElements($this->node->childNodes, $nodeName);
25
26
        $variables = [];
27
        foreach ($children as $child) {
28
            $name = $this->readAttrText('name', '', $child);
29
            $value = $this->readAttrText('value', '', $child);
30
31
            $variables[$name] = $value;
32
        }
33
34
        return $variables;
35
    }
36
}
37