ExceptionThrowingXMLReader::next()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace SimpleXmlReader;
4
5
use DOMNode;
6
use XMLReader;
7
8
class ExceptionThrowingXMLReader extends XMLReader
9
{
10
    public function open($URI, $encoding = null, $options = 0)
11
    {
12
        return static::ensureSuccess(@parent::open($URI, $encoding, $options), 'open');
13
    }
14
15
    static protected function ensureSuccess($returnValue, $operation)
16
    {
17
        if (! $returnValue) {
18
            throw new XmlException("Error while performing XMLReader::$operation");
19
        }
20
        return $returnValue;
21
    }
22
23
    public function expand($baseNode = null)
24
    {
25
        if (null === $baseNode) {
26
            return static::ensureSuccess(@parent::expand(), 'expend');
27
        } else {
28
            return static::ensureSuccess(@parent::expand($baseNode), 'expend');
29
        }
30
    }
31
32
    public function read()
33
    {
34
        return static::ensureSuccess(@parent::read(), 'read');
35
    }
36
37
    public function tryRead()
38
    {
39
        // We're ignoring any PHP errors, as we are trying to read
40
        return @parent::read();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (read() instead of tryRead()). Are you sure this is correct? If so, you might want to change this to $this->read().

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...
41
    }
42
43
    public function next($localName = null)
44
    {
45
        if (null === $localName) {
46
            return static::ensureSuccess(@parent::next(), 'next');
47
        }
48
49
        return static::ensureSuccess(@parent::next($localName), 'next');
50
    }
51
52
    public function tryNext($localName = null)
53
    {
54
        // We're ignoring any PHP errors, as we are trying to fetch the next element
55
        if (null === $localName) {
56
            return @parent::next();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (next() instead of tryNext()). Are you sure this is correct? If so, you might want to change this to $this->next().

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...
57
        }
58
59
        return @parent::next($localName);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (next() instead of tryNext()). Are you sure this is correct? If so, you might want to change this to $this->next().

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...
60
    }
61
}
62