Completed
Push — development ( ff30d7...36da13 )
by Dylan David
01:46
created
Ptypes/Exceptions/InvalidArgument.php 3 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -6,13 +6,13 @@
 block discarded – undo
6 6
 
7 7
 class InvalidArgument extends Exception
8 8
 {
9
-    public function __construct($message="Invalid Argument!", $code = 1, Exception $previous = null) 
9
+	public function __construct($message="Invalid Argument!", $code = 1, 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
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
 
7 7
 class InvalidArgument extends Exception
8 8
 {
9
-    public function __construct($message="Invalid Argument!", $code = 1, Exception $previous = null) 
9
+    public function __construct($message = "Invalid Argument!", $code = 1, Exception $previous = null) 
10 10
 	{
11 11
         parent::__construct($message, $code, $previous);
12 12
     }
Please login to merge, or discard this patch.
Braces   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -6,13 +6,13 @@
 block discarded – undo
6 6
 
7 7
 class InvalidArgument extends Exception
8 8
 {
9
-    public function __construct($message="Invalid Argument!", $code = 1, Exception $previous = null) 
10
-	{
9
+    public function __construct($message="Invalid Argument!", $code = 1, 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
Please login to merge, or discard this patch.
Ptypes/Exceptions/StackUnderflow.php 3 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -6,13 +6,13 @@
 block discarded – undo
6 6
 
7 7
 class StackUnderflow extends Exception
8 8
 {
9
-    public function __construct($message="Stack Underflow!", $code = 3, Exception $previous = null) 
9
+	public function __construct($message="Stack Underflow!", $code = 3, 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
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
 
7 7
 class StackUnderflow extends Exception
8 8
 {
9
-    public function __construct($message="Stack Underflow!", $code = 3, Exception $previous = null) 
9
+    public function __construct($message = "Stack Underflow!", $code = 3, Exception $previous = null) 
10 10
 	{
11 11
         parent::__construct($message, $code, $previous);
12 12
     }
Please login to merge, or discard this patch.
Braces   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -6,13 +6,13 @@
 block discarded – undo
6 6
 
7 7
 class StackUnderflow extends Exception
8 8
 {
9
-    public function __construct($message="Stack Underflow!", $code = 3, Exception $previous = null) 
10
-	{
9
+    public function __construct($message="Stack Underflow!", $code = 3, 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
Please login to merge, or discard this patch.
Ptypes/Exceptions/StackOverflow.php 3 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -6,13 +6,13 @@
 block discarded – undo
6 6
 
7 7
 class StackOverflow extends Exception
8 8
 {
9
-    public function __construct($message="Stack Overflow!", $code = 2, Exception $previous = null) 
9
+	public function __construct($message="Stack Overflow!", $code = 2, 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
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
 
7 7
 class StackOverflow extends Exception
8 8
 {
9
-    public function __construct($message="Stack Overflow!", $code = 2, Exception $previous = null) 
9
+    public function __construct($message = "Stack Overflow!", $code = 2, Exception $previous = null) 
10 10
 	{
11 11
         parent::__construct($message, $code, $previous);
12 12
     }
Please login to merge, or discard this patch.
Braces   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -6,13 +6,13 @@
 block discarded – undo
6 6
 
7 7
 class StackOverflow extends Exception
8 8
 {
9
-    public function __construct($message="Stack Overflow!", $code = 2, Exception $previous = null) 
10
-	{
9
+    public function __construct($message="Stack Overflow!", $code = 2, 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
Please login to merge, or discard this patch.
Ptypes/Exceptions/UnexpectedType.php 3 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -6,13 +6,13 @@
 block discarded – undo
6 6
 
7 7
 class UnexpectedType extends Exception
8 8
 {
9
-    public function __construct($message="Unexpected Type given!", $code = 0, Exception $previous = null) 
9
+	public function __construct($message="Unexpected Type given!", $code = 0, 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
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
 
7 7
 class UnexpectedType extends Exception
8 8
 {
9
-    public function __construct($message="Unexpected Type given!", $code = 0, Exception $previous = null) 
9
+    public function __construct($message = "Unexpected Type given!", $code = 0, Exception $previous = null) 
10 10
 	{
11 11
         parent::__construct($message, $code, $previous);
12 12
     }
Please login to merge, or discard this patch.
Braces   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -6,13 +6,13 @@
 block discarded – undo
6 6
 
7 7
 class UnexpectedType extends Exception
8 8
 {
9
-    public function __construct($message="Unexpected Type given!", $code = 0, Exception $previous = null) 
10
-	{
9
+    public function __construct($message="Unexpected Type given!", $code = 0, 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
Please login to merge, or discard this patch.
Ptypes/Stack.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
 	 */
30 30
 	public function __construct($maxsize)
31 31
 	{
32
-		if(gettype($maxsize) != "integer"){throw new UnexpectedType("Expected an integer, got: ".gettype($maxsize));}	
33
-		if($maxsize < 2) {throw new InvalidArgument("Stack has a minimum size of 2!");}
32
+		if (gettype($maxsize) != "integer") {throw new UnexpectedType("Expected an integer, got: " . gettype($maxsize)); }	
33
+		if ($maxsize < 2) {throw new InvalidArgument("Stack has a minimum size of 2!"); }
34 34
 		
35 35
 		$this->maxsize = $maxsize;
36 36
 		$this->items = array();	
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	 */
45 45
 	public function push($item)
46 46
 	{
47
-		if($this->top == $this->maxsize) {throw new StackOverflow("Pushing this item would overflow the stack (exceed the max stack size)!");}
47
+		if ($this->top == $this->maxsize) {throw new StackOverflow("Pushing this item would overflow the stack (exceed the max stack size)!"); }
48 48
 		$this->items[$this->top++] = $item;
49 49
 		return $this;
50 50
 	}
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 */
55 55
 	public function pop()
56 56
 	{
57
-		if($this->top == 0) {throw new StackUnderflow("Cannot pop an empty stack!");}
57
+		if ($this->top == 0) {throw new StackUnderflow("Cannot pop an empty stack!"); }
58 58
 		unset($this->items[$this->top--]);
59 59
 		return $this;
60 60
 	}
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 	 */
87 87
 	public function peek()
88 88
 	{
89
-		if($this->top == 0) {return null;}
89
+		if ($this->top == 0) {return null; }
90 90
 		return $this->items[$this->top-1];
91 91
 	}
92 92
 	
@@ -111,10 +111,10 @@  discard block
 block discarded – undo
111 111
 	public function __toString()
112 112
 	{
113 113
 		$str = "Stack:\n";
114
-		$str .= ((string)$this->items[$this->top-1])."   <-- top\n";
115
-		for($i = $this->top-2; $i >= 0; $i--)
114
+		$str .= ((string)$this->items[$this->top-1]) . "   <-- top\n";
115
+		for ($i = $this->top-2; $i >= 0; $i--)
116 116
 		{
117
-			$str .= ((string)$this->items[$i])."\n";
117
+			$str .= ((string)$this->items[$i]) . "\n";
118 118
 		}
119 119
 		
120 120
 		return $str;
Please login to merge, or discard this patch.
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -29,8 +29,12 @@  discard block
 block discarded – undo
29 29
 	 */
30 30
 	public function __construct($maxsize)
31 31
 	{
32
-		if(gettype($maxsize) != "integer"){throw new UnexpectedType("Expected an integer, got: ".gettype($maxsize));}	
33
-		if($maxsize < 2) {throw new InvalidArgument("Stack has a minimum size of 2!");}
32
+		if(gettype($maxsize) != "integer")
33
+		{
34
+throw new UnexpectedType("Expected an integer, got: ".gettype($maxsize));}	
35
+		if($maxsize < 2)
36
+		{
37
+throw new InvalidArgument("Stack has a minimum size of 2!");}
34 38
 		
35 39
 		$this->maxsize = $maxsize;
36 40
 		$this->items = array();	
@@ -44,7 +48,9 @@  discard block
 block discarded – undo
44 48
 	 */
45 49
 	public function push($item)
46 50
 	{
47
-		if($this->top == $this->maxsize) {throw new StackOverflow("Pushing this item would overflow the stack (exceed the max stack size)!");}
51
+		if($this->top == $this->maxsize)
52
+		{
53
+throw new StackOverflow("Pushing this item would overflow the stack (exceed the max stack size)!");}
48 54
 		$this->items[$this->top++] = $item;
49 55
 		return $this;
50 56
 	}
@@ -54,7 +60,9 @@  discard block
 block discarded – undo
54 60
 	 */
55 61
 	public function pop()
56 62
 	{
57
-		if($this->top == 0) {throw new StackUnderflow("Cannot pop an empty stack!");}
63
+		if($this->top == 0)
64
+		{
65
+throw new StackUnderflow("Cannot pop an empty stack!");}
58 66
 		unset($this->items[$this->top--]);
59 67
 		return $this;
60 68
 	}
@@ -86,7 +94,9 @@  discard block
 block discarded – undo
86 94
 	 */
87 95
 	public function peek()
88 96
 	{
89
-		if($this->top == 0) {return null;}
97
+		if($this->top == 0)
98
+		{
99
+return null;}
90 100
 		return $this->items[$this->top-1];
91 101
 	}
92 102
 	
Please login to merge, or discard this patch.
Ptypes/DoublyLinkedList.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 	public $next = null, $prev = null; //A reference to the next and previous node
13 13
 	public $data = null; //Data or a reference to data
14 14
 	
15
-	public function __construct($data=null) 
15
+	public function __construct($data = null) 
16 16
 	{
17 17
 		$this->data = $data;
18 18
 	}
@@ -143,23 +143,23 @@  discard block
 block discarded – undo
143 143
 	
144 144
 	public function get($index)
145 145
 	{
146
-		if($index < 0 || $index > $this->size-1)
146
+		if ($index < 0 || $index > $this->size-1)
147 147
 		{
148 148
 			throw new IndexOutOfBounds("The given index is out of bounds!")
149 149
 		}
150 150
 		
151
-		if($index == 0)
151
+		if ($index == 0)
152 152
 		{
153 153
 			return $this->firstNode;
154 154
 		}
155 155
 		
156
-		if($index == $this->size-1)
156
+		if ($index == $this->size-1)
157 157
 		{
158 158
 			return $this->lastNode;
159 159
 		}
160 160
 		
161 161
 		$node = $this->firstNode;
162
-		for($i = 1; $i <= $index; $i++)
162
+		for ($i = 1; $i <= $index; $i++)
163 163
 		{
164 164
 			$node = $node->next;
165 165
 		}
Please login to merge, or discard this patch.
Braces   +29 added lines, -11 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 	public $next = null, $prev = null; //A reference to the next and previous node
13 13
 	public $data = null; //Data or a reference to data
14 14
 	
15
-	public function __construct($data=null) 
15
+	public function __construct($data=null)
16 16
 	{
17 17
 		$this->data = $data;
18 18
 	}
@@ -24,13 +24,19 @@  discard block
 block discarded – undo
24 24
 	
25 25
 	private $size = 0;
26 26
 	
27
-	public function __construct() {}
27
+	public function __construct()
28
+	{
29
+}
28 30
 	
29 31
 	public function insert_after($node, $newNode)
30 32
 	{
31 33
 		//type checks
32
-		if (get_class($node) != "DLNode") {throw new InvalidArgument("Expected a DLNode, got: " . get_class($node)); }
33
-		if (get_class($newNode) != "DLNode") {throw new InvalidArgument("Expected a DLNode, got: " . get_class($newNode)); }
34
+		if (get_class($node) != "DLNode")
35
+		{
36
+throw new InvalidArgument("Expected a DLNode, got: " . get_class($node)); }
37
+		if (get_class($newNode) != "DLNode")
38
+		{
39
+throw new InvalidArgument("Expected a DLNode, got: " . get_class($newNode)); }
34 40
 		
35 41
 		$newNode->prev = $node;
36 42
 		if ($node->next == null)
@@ -50,8 +56,12 @@  discard block
 block discarded – undo
50 56
 	public function insert_before($node, $newNode)
51 57
 	{
52 58
 		//type checks
53
-		if (get_class($node) != "DLNode") {throw new InvalidArgument("Expected a DLNode, got: " . get_class($node)); }
54
-		if (get_class($newNode) != "DLNode") {throw new InvalidArgument("Expected a DLNode, got: " . get_class($newNode)); }
59
+		if (get_class($node) != "DLNode")
60
+		{
61
+throw new InvalidArgument("Expected a DLNode, got: " . get_class($node)); }
62
+		if (get_class($newNode) != "DLNode")
63
+		{
64
+throw new InvalidArgument("Expected a DLNode, got: " . get_class($newNode)); }
55 65
 		
56 66
 		$newNode->next = $node;
57 67
 		if ($node->prev == null)
@@ -69,9 +79,11 @@  discard block
 block discarded – undo
69 79
 	}
70 80
 	
71 81
 	public function insert_beginning($newNode)
72
-	{	
82
+	{
73 83
 		//type checks
74
-		if (get_class($newNode) != "DLNode") {throw new InvalidArgument("Expected a DLNode, got: " . get_class($newNode)); }
84
+		if (get_class($newNode) != "DLNode")
85
+		{
86
+throw new InvalidArgument("Expected a DLNode, got: " . get_class($newNode)); }
75 87
 		
76 88
 		if ($this->firstNode == null)
77 89
 		{
@@ -103,13 +115,17 @@  discard block
 block discarded – undo
103 115
 	public function contains($node)
104 116
 	{
105 117
 		//check this so we could possibly avoid list traversal
106
-		if ($node == $this->firstNode || $node == $this->lastNode) {return true; }
118
+		if ($node == $this->firstNode || $node == $this->lastNode)
119
+		{
120
+return true; }
107 121
 		
108 122
 		//traverse the list and try to find the node
109 123
 		$n = $this->firstNode->next; //we can start one node ahead as we already checked the firstNode
110 124
 		while ($n != null)
111 125
 		{
112
-			if ($n == $node) {return true; }
126
+			if ($n == $node)
127
+			{
128
+return true; }
113 129
 			$n = $n->next;
114 130
 		}
115 131
 		
@@ -119,7 +135,9 @@  discard block
 block discarded – undo
119 135
 	public function remove($node)
120 136
 	{
121 137
 		//check if the node exists
122
-		if ($this->contains($node) == false) { throw new InvalidArgument("The node given does not exist in this list!"); }
138
+		if ($this->contains($node) == false)
139
+		{
140
+throw new InvalidArgument("The node given does not exist in this list!"); }
123 141
 		
124 142
 		if ($node->prev == null)
125 143
 		{
Please login to merge, or discard this patch.
Ptypes/Exceptions/IndexOutOfBounds.php 3 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -6,13 +6,13 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
Braces   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -6,13 +6,13 @@
 block discarded – undo
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
Please login to merge, or discard this patch.