Completed
Push — master ( 9387a7...15e170 )
by Siro Díaz
02:50
created

ArrayList::pop()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
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
        $this->position = 0;
17
    }
18
19
    public function insert($index, $data) {
20
        
21
    }
22
    
23
    public function clear() {
24
        $this->data = [];
25
    }
26
    
27
    public function get($index) {
28
29
    }
30
31
    public function getAll() {
32
33
    }
34
35
    public function empty() : bool {
36
        return $this->size === 0;
37
    }
38
    
39
    /**
40
     * Removes and returns the last node in the list.
41
     *
42
     * @return mixed data in node.
43
     */
44
    public function pop() {
45
46
    }
47
48
    public function delete($index) {
49
        unset($this->data[$index]);
50
    }
51
    
52
    /**
53
     * Returns the array size.
54
     *
55
     * @return int the length
56
     */
57
    public function size() : int {
58
        return $this->size;
59
    }
60
61
    /**
62
     * Returns array stored in the data attribute.
63
     *
64
     * @return array data stored in all nodes.
65
     */
66
    public function toArray() : array {
67
        return $this->data;
68
    }
69
70
    /**
71
     * Reset the cursor position.
72
     */
73
    public function rewind() {
74
        $this->position = 0;
75
        $this->current = $this->data[$this->position];
76
    }
77
78
    /**
79
     * Returns the current node data.
80
     *
81
     * @return mixed
82
     */
83
    public function current() {
84
        return $this->current;
85
    }
86
87
    /**
88
     * Key or index that indicates the cursor position.
89
     *
90
     * @return integer The current position.
91
     */
92
    public function key() {
93
        return $this->position;
94
    }
95
96
    /**
97
     * Move the cursor to the next node and increments the
98
     * position counter.
99
     */
100
    public function next() {
101
        ++$this->position;
102
        $this->current = $this->data[$this->position];
103
    }
104
105
    /**
106
     * Returns if the current pointer position is valid.
107
     *
108
     * @return boolean true if pointer is not last, else false.
109
     */
110
    public function valid() {
111
        return $this->position < $this->size;
112
    }
113
114
    /**
115
     * Binds to count() method. This is equal to make $this->list->size().
116
     *
117
     * @return integer the list size. 0 if it is empty.
118
     */
119
    public function count() {
120
        return $this->size;
121
    }
122
123
    public function offsetSet($offset, $valor) {
124
        //TODO
125
        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...
126
            // $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...
127
        } 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...
128
            // $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...
129
        }
130
    }
131
    
132
    public function offsetExists($offset) {
133
        //TODO
134
        return false;
135
        // 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...
136
    }
137
138
    public function offsetUnset($offset) {
139
        //TODO
140
        // 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...
141
    }
142
143
    public function offsetGet($offset) {
144
        //TODO
145
        return false;
146
        // 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...
147
    }
148
}