Completed
Push — master ( f3b505...9387a7 )
by Siro Díaz
09:13
created

ArrayList::offsetSet()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

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 3
nc 2
nop 2
1
<?php
2
3
namespace DataStructures\Lists;
4
5
use DataStructures\Lists\Interfaces\ListInterface;
6
7
class ArrayList implements ListInterface {
8
    private $data;
9
    private $current;
10
    private $position;
11
    private $size;
12
13
    public function __construct() {
14
        $this->data = [];
15
        $this->size = 0;
16
    }
17
18
    public function insert($index, $data) {
19
20
    }
21
    
22
    public function clear() {
23
24
    }
25
    
26
    public function get($index) {
27
28
    }
29
30
    public function getAll() {
31
32
    }
33
34
    public function empty() : bool {
35
        return true;
36
    }
37
    
38
    public function delete($index) {
39
40
    }
41
    
42
    public function size() : int {
43
        return 0;
44
    }
45
46
    public function toArray() : array {
47
        return [];
48
    }
49
50
    /**
51
     * Reset the cursor position.
52
     */
53
    public function rewind() {
54
        $this->position = 0;
55
        $this->current = &$this->head;
0 ignored issues
show
Bug introduced by
The property head does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
56
    }
57
58
    /**
59
     * Returns the current node data.
60
     *
61
     * @return mixed
62
     */
63
    public function current() {
64
        return $this->current->data;
65
    }
66
67
    /**
68
     * Key or index that indicates the cursor position.
69
     *
70
     * @return integer The current position.
71
     */
72
    public function key() {
73
        return $this->position;
74
    }
75
76
    /**
77
     * Move the cursor to the next node and increments the
78
     * position counter.
79
     */
80
    public function next() {
81
        ++$this->position;
82
        $this->current = $this->current->next;
83
    }
84
85
    /**
86
     * Returns if the current pointer position is valid.
87
     *
88
     * @return boolean true if pointer is not last, else false.
89
     */
90
    public function valid() {
91
        return $this->position < $this->size;
92
    }
93
94
    /**
95
     * Binds to count() method. This is equal to make $this->list->size().
96
     *
97
     * @return integer the list size. 0 if it is empty.
98
     */
99
    public function count() {
100
        return $this->size;
101
    }
102
103
    public function offsetSet($offset, $valor) {
104
        //TODO
105
        if (is_null($offset)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
106
            // $this->contenedor[] = $valor;
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
107
        } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
108
            // $this->contenedor[$offset] = $valor;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
109
        }
110
    }
111
    
112
    public function offsetExists($offset) {
113
        //TODO
114
        return false;
115
        // return isset($this->contenedor[$offset]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
116
    }
117
118
    public function offsetUnset($offset) {
119
        //TODO
120
        // unset($this->contenedor[$offset]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
82% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
121
    }
122
123
    public function offsetGet($offset) {
124
        //TODO
125
        return false;
126
        // return isset($this->contenedor[$offset]) ? $this->contenedor[$offset] : null;
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
127
    }
128
}