Completed
Push — master ( 6054f8...3b037a )
by Matthias
24:24
created

XMLReader   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 0
dl 30
loc 30
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B readNext() 16 16 6

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Cauditor\Analyzers;
4
5
use XMLReader as OriginalXMLReader;
6
7
/**
8
 * @author Matthias Mullie <[email protected]>
9
 * @copyright Copyright (c) 2016, Matthias Mullie. All rights reserved.
10
 * @license LICENSE MIT
11
 */
12 View Code Duplication
class XMLReader extends OriginalXMLReader
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
{
14
    /**
15
     * This is a blend of XMLReader's read & next, in that it accepts a node
16
     * name to search for, but it doesn't assume the node if on the same level
17
     * in DOM hierarchy as where you're currently at: it won't skip children &
18
     * it will cross parents (unless.
19
     *
20
     * @param string $name   Name of the node we're looking for.
21
     * @param string $parent Name of parent node(s) to stay inside of.
22
     *
23
     * @return bool
24
     */
25
    public function readNext($name, $parent = null)
26
    {
27
        while ($this->read()) {
28
            // next node
29
            if ($this->localName === $name && $this->nodeType === self::ELEMENT) {
30
                return true;
31
            }
32
33
            // stop processing at and of this node
34
            if ($this->localName === $parent && $this->nodeType === self::END_ELEMENT) {
35
                return false;
36
            }
37
        }
38
39
        return false;
40
    }
41
}
42