@@ -15,7 +15,7 @@ |
||
| 15 | 15 | * |
| 16 | 16 | * @param object $data |
| 17 | 17 | */ |
| 18 | - public function __construct($data=null) |
|
| 18 | + public function __construct($data = null) |
|
| 19 | 19 | { |
| 20 | 20 | $this->data = $data; |
| 21 | 21 | } |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | * |
| 16 | 16 | * @param object $data |
| 17 | 17 | */ |
| 18 | - public function __construct($data=null) |
|
| 18 | + public function __construct($data=null) |
|
| 19 | 19 | { |
| 20 | 20 | $this->data = $data; |
| 21 | 21 | } |
@@ -23,12 +23,12 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | private function validate_parameter($node) |
| 25 | 25 | { |
| 26 | - if(gettype($node) != "object") |
|
| 26 | + if (gettype($node) != "object") |
|
| 27 | 27 | { |
| 28 | 28 | throw new UnexpectedType("Expected a Ptypes\DLNode, got: " . gettype($node)); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - if(get_class($node) != "Ptypes\DLNode") |
|
| 31 | + if (get_class($node) != "Ptypes\DLNode") |
|
| 32 | 32 | { |
| 33 | 33 | throw new UnexpectedType("Expected a Ptypes\DLNode, got: " . get_class($node)); |
| 34 | 34 | } |
@@ -230,28 +230,28 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | public function get($index) |
| 232 | 232 | { |
| 233 | - if(gettype($index) != "integer") |
|
| 233 | + if (gettype($index) != "integer") |
|
| 234 | 234 | { |
| 235 | - throw new UnexpectedType("Expected an integer, got: ".gettype($index)); |
|
| 235 | + throw new UnexpectedType("Expected an integer, got: " . gettype($index)); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - if($index < 0 || $index > $this->size-1) |
|
| 238 | + if ($index < 0 || $index > $this->size-1) |
|
| 239 | 239 | { |
| 240 | 240 | throw new IndexOutOfBounds("The given index is out of bounds!"); |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - if($index == 0) |
|
| 243 | + if ($index == 0) |
|
| 244 | 244 | { |
| 245 | 245 | return $this->firstNode; |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - if($index == $this->size-1) |
|
| 248 | + if ($index == $this->size-1) |
|
| 249 | 249 | { |
| 250 | 250 | return $this->lastNode; |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | $node = $this->firstNode; |
| 254 | - for($i = 1; $i <= $index; $i++) |
|
| 254 | + for ($i = 1; $i <= $index; $i++) |
|
| 255 | 255 | { |
| 256 | 256 | $node = $node->next; |
| 257 | 257 | } |
@@ -19,7 +19,9 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | private $size = 0; |
| 21 | 21 | |
| 22 | - public function __construct() {} |
|
| 22 | + public function __construct() |
|
| 23 | + { |
|
| 24 | +} |
|
| 23 | 25 | |
| 24 | 26 | private function validate_parameter($node) |
| 25 | 27 | { |
@@ -98,7 +100,7 @@ discard block |
||
| 98 | 100 | * @param DLNode $newNode |
| 99 | 101 | */ |
| 100 | 102 | public function insert_beginning($newNode) |
| 101 | - { |
|
| 103 | + { |
|
| 102 | 104 | //type checks |
| 103 | 105 | $this->validate_parameter($newNode); |
| 104 | 106 | |
@@ -165,7 +167,7 @@ discard block |
||
| 165 | 167 | $this->validate_parameter($node); |
| 166 | 168 | |
| 167 | 169 | //check this so we could possibly avoid list traversal |
| 168 | - if ($node == $this->firstNode || $node == $this->lastNode) |
|
| 170 | + if ($node == $this->firstNode || $node == $this->lastNode) |
|
| 169 | 171 | { |
| 170 | 172 | return true; |
| 171 | 173 | } |
@@ -174,7 +176,7 @@ discard block |
||
| 174 | 176 | $n = $this->firstNode->next; //we can start one node ahead as we already checked the firstNode |
| 175 | 177 | while ($n != null) |
| 176 | 178 | { |
| 177 | - if ($n == $node) |
|
| 179 | + if ($n == $node) |
|
| 178 | 180 | { |
| 179 | 181 | return true; |
| 180 | 182 | } |
@@ -196,8 +198,8 @@ discard block |
||
| 196 | 198 | $this->validate_parameter($node); |
| 197 | 199 | |
| 198 | 200 | //check if the node exists |
| 199 | - if ($this->contains($node) === false) |
|
| 200 | - { |
|
| 201 | + if ($this->contains($node) === false) |
|
| 202 | + { |
|
| 201 | 203 | throw new InvalidArgument("The node given does not exist in this list!"); |
| 202 | 204 | } |
| 203 | 205 | |