GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

NodeMap   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 98
Duplicated Lines 11.22 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 17
lcom 1
cbo 1
dl 11
loc 98
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __contruct() 0 4 1
A count() 0 4 1
A isEmpty() 0 4 1
A rewind() 0 4 1
A current() 0 4 1
A key() 0 4 1
A next() 0 4 1
A valid() 0 4 1
A lookup() 11 11 2
A lookupFrom() 0 16 3
A delete() 0 13 2
A exists() 0 4 1
A insert() 0 4 1

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 Letournel\PathFinder\Core;
4
5
class NodeMap implements \Countable, \Iterator
6
{
7
    private
8
        $map;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $map.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
9
    
10
    public function __contruct()
11
    {
12
        $this->map = array();
13
    }
14
    
15
    public function count()
16
    {
17
        return count($this->map);
18
    }
19
    
20
    public function isEmpty()
21
    {
22
        return empty($this->map);
23
    }
24
    
25
    public function rewind()
26
    {
27
        rewind($this->map);
28
    }
29
    
30
    public function current()
31
    {
32
        return current($this->map);
33
    }
34
    
35
    public function key()
36
    {
37
        return key($this->map);
38
    }
39
    
40
    public function next()
41
    {
42
        return next($this->map);
43
    }
44
    
45
    public function valid()
46
    {
47
        return valid($this->map);
48
    }
49
    
50 View Code Duplication
    public function lookup(Node $node)
0 ignored issues
show
Duplication introduced by
This method 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...
51
    {
52
        $id = $node->getId();
53
        
54
        if(array_key_exists($id, $this->map))
55
        {
56
            return $this->map[$id];
57
        }
58
        
59
        return null;
60
    }
61
    
62
    public function lookupFrom(Node $node)
63
    {
64
        $path = array();
65
        while($node instanceof Node)
66
        {
67
            array_unshift($path, $node);
68
            $node = $this->lookup($node);
69
            
70
            if(in_array($node, $path))
71
            {
72
                break;
73
            }
74
        }
75
        
76
        return $path;
77
    }
78
    
79
    public function delete(Node $node)
80
    {
81
        $id = $node->getId();
82
        $value = null;
83
        
84
        if(array_key_exists($id, $this->map))
85
        {
86
            $value = $this->map[$id];
87
            unset($this->map[$id]);
88
        }
89
        
90
        return $value;
91
    }
92
    
93
    public function exists(Node $node)
94
    {
95
        return array_key_exists($node->getId(), $this->map);
96
    }
97
    
98
    public function insert(Node $node, $value = true)
99
    {
100
        $this->map[$node->getId()] = $value;
101
    }
102
}
103