@@ -6,13 +6,13 @@ |
||
| 6 | 6 | |
| 7 | 7 | class IndexOutOfBounds extends Exception |
| 8 | 8 | { |
| 9 | - public function __construct($message="Index is Out Of Bounds!", $code = 4, Exception $previous = null) |
|
| 9 | + public function __construct($message="Index is Out Of Bounds!", $code = 4, Exception $previous = null) |
|
| 10 | 10 | { |
| 11 | - parent::__construct($message, $code, $previous); |
|
| 12 | - } |
|
| 11 | + parent::__construct($message, $code, $previous); |
|
| 12 | + } |
|
| 13 | 13 | |
| 14 | - public function __toString() |
|
| 14 | + public function __toString() |
|
| 15 | 15 | { |
| 16 | - return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; |
|
| 17 | - } |
|
| 16 | + return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; |
|
| 17 | + } |
|
| 18 | 18 | } |
| 19 | 19 | \ No newline at end of file |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | |
| 7 | 7 | class IndexOutOfBounds extends Exception |
| 8 | 8 | { |
| 9 | - public function __construct($message="Index is Out Of Bounds!", $code = 4, Exception $previous = null) |
|
| 9 | + public function __construct($message = "Index is Out Of Bounds!", $code = 4, Exception $previous = null) |
|
| 10 | 10 | { |
| 11 | 11 | parent::__construct($message, $code, $previous); |
| 12 | 12 | } |
@@ -6,13 +6,13 @@ |
||
| 6 | 6 | |
| 7 | 7 | class IndexOutOfBounds extends Exception |
| 8 | 8 | { |
| 9 | - public function __construct($message="Index is Out Of Bounds!", $code = 4, Exception $previous = null) |
|
| 10 | - { |
|
| 9 | + public function __construct($message="Index is Out Of Bounds!", $code = 4, Exception $previous = null) |
|
| 10 | + { |
|
| 11 | 11 | parent::__construct($message, $code, $previous); |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | - public function __toString() |
|
| 15 | - { |
|
| 14 | + public function __toString() |
|
| 15 | + { |
|
| 16 | 16 | return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; |
| 17 | 17 | } |
| 18 | 18 | } |
| 19 | 19 | \ No newline at end of file |
@@ -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 | } |
@@ -167,9 +167,9 @@ discard block |
||
| 167 | 167 | $this->validate_parameter($node); |
| 168 | 168 | |
| 169 | 169 | $n = $this->firstNode; |
| 170 | - while($n != null) |
|
| 170 | + while ($n != null) |
|
| 171 | 171 | { |
| 172 | - if($n == $node) |
|
| 172 | + if ($n == $node) |
|
| 173 | 173 | { |
| 174 | 174 | return true; |
| 175 | 175 | } |
@@ -226,28 +226,28 @@ discard block |
||
| 226 | 226 | */ |
| 227 | 227 | public function get($index) |
| 228 | 228 | { |
| 229 | - if(gettype($index) != "integer") |
|
| 229 | + if (gettype($index) != "integer") |
|
| 230 | 230 | { |
| 231 | - throw new UnexpectedType("Expected an integer, got: ".gettype($index)); |
|
| 231 | + throw new UnexpectedType("Expected an integer, got: " . gettype($index)); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - if($index < 0 || $index > $this->size-1) |
|
| 234 | + if ($index < 0 || $index > $this->size-1) |
|
| 235 | 235 | { |
| 236 | 236 | throw new IndexOutOfBounds("The given index is out of bounds!"); |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - if($index == 0) |
|
| 239 | + if ($index == 0) |
|
| 240 | 240 | { |
| 241 | 241 | return $this->firstNode; |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | - if($index == $this->size-1) |
|
| 244 | + if ($index == $this->size-1) |
|
| 245 | 245 | { |
| 246 | 246 | return $this->lastNode; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | $node = $this->firstNode; |
| 250 | - for($i = 1; $i <= $index; $i++) |
|
| 250 | + for ($i = 1; $i <= $index; $i++) |
|
| 251 | 251 | { |
| 252 | 252 | $node = $node->next; |
| 253 | 253 | } |
@@ -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 | { |
@@ -100,7 +102,7 @@ discard block |
||
| 100 | 102 | * @param DLNode $newNode |
| 101 | 103 | */ |
| 102 | 104 | public function insert_beginning($newNode) |
| 103 | - { |
|
| 105 | + { |
|
| 104 | 106 | //type checks |
| 105 | 107 | $this->validate_parameter($newNode); |
| 106 | 108 | |
@@ -192,8 +194,8 @@ discard block |
||
| 192 | 194 | $this->validate_parameter($node); |
| 193 | 195 | |
| 194 | 196 | //check if the node exists |
| 195 | - if ($this->contains($node) === false) |
|
| 196 | - { |
|
| 197 | + if ($this->contains($node) === false) |
|
| 198 | + { |
|
| 197 | 199 | throw new InvalidArgument("The node given does not exist in this list!"); |
| 198 | 200 | } |
| 199 | 201 | |
@@ -213,13 +213,13 @@ |
||
| 213 | 213 | public function it_can_get_size_and_count() |
| 214 | 214 | { |
| 215 | 215 | $list = new DoublyLinkedList(); |
| 216 | - for($i = 0; $i < 10; $i++) |
|
| 216 | + for ($i = 0; $i < 10; $i++) |
|
| 217 | 217 | { |
| 218 | 218 | $list->insert(new DLNode($i)); |
| 219 | 219 | } |
| 220 | 220 | $n = new DLNode(11); |
| 221 | 221 | $list->insert($n); |
| 222 | 222 | $list->remove($n); |
| 223 | - $this->assertEquals($list->size() + count($list), 20); //10 + 10 = 10 + 10 i.e: 20 = 20 |
|
| 223 | + $this->assertEquals($list->size()+count($list), 20); //10 + 10 = 10 + 10 i.e: 20 = 20 |
|
| 224 | 224 | } |
| 225 | 225 | } |
| 226 | 226 | \ No newline at end of file |