Element::getAttribute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Thruster\Component\XMLIterator;
4
5
use RuntimeException;
6
7
/**
8
 * Class Element
9
 *
10
 * @package Thruster\Component\XMLIterator
11
 * @author  Aurimas Niekis <[email protected]>
12
 */
13
class Element extends Node
14
{
15
    private $name_;
16
    private $attributes_;
17
18 18
    public function __construct(XMLReader $reader)
19
    {
20 18
        parent::__construct($reader);
21
22 18
        $this->initializeFrom($reader);
23 18
    }
24
25 1
    public function getXMLElementAround($innerXML = '')
26
    {
27 1
        return XMLBuild::wrapTag($this->name_, $this->attributes_, $innerXML);
28
    }
29
30
    public function getAttributes()
31
    {
32
        return $this->attributes_;
33
    }
34
35
    public function getAttribute(string $name, $default = null)
36
    {
37
        return $this->attributes_[$name] ?? $default;
38
    }
39
40
    public function __toString()
41
    {
42
        return $this->name_;
43
    }
44
45 18
    private function initializeFrom(XMLReader $reader)
46
    {
47 18
        if ($reader->nodeType !== XMLReader::ELEMENT) {
48
            $node = new Node($reader);
49
50
            throw new RuntimeException(sprintf(
51
                'Reader must be at an XMLReader::ELEMENT, is XMLReader::%s given.',
52
                $node->getNodeTypeName()
53
            ));
54
        }
55
56 18
        $this->name_       = $reader->name;
57 18
        $this->attributes_ = parent::getAttributes()->getArrayCopy();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getAttributes() instead of initializeFrom()). Are you sure this is correct? If so, you might want to change this to $this->getAttributes().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
58 18
    }
59
}
60