Completed
Push — development ( 2d042e...b2c933 )
by Dylan David
01:38
created
Ptypes/Test/BinaryTreeTest.php 1 patch
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
 use Ptypes\TreeNode;
7 7
 
8 8
 class BinaryTreeTest extends \PHPUnit_Framework_TestCase
9
-{	
9
+{
10 10
 	/** @test */
11 11
 	public function it_can_insert()
12 12
 	{
Please login to merge, or discard this patch.
Ptypes/TreeNode.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,9 +11,9 @@
 block discarded – undo
11 11
 	public $left;
12 12
 	public $right;
13 13
 	
14
-	public function __construct($value, $data=null)
14
+	public function __construct($value, $data = null)
15 15
 	{
16
-		if(gettype($value) != "integer" && gettype($value) != "int" && gettype($value) != "double")
16
+		if (gettype($value) != "integer" && gettype($value) != "int" && gettype($value) != "double")
17 17
 		{
18 18
 			throw new InvalidArgument("Expected a number, got: " . gettype($value) . "!");
19 19
 		}
Please login to merge, or discard this patch.
Ptypes/BinaryTree.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -23,18 +23,18 @@  discard block
 block discarded – undo
23 23
 	{
24 24
 		$this->validate_parameter($node);
25 25
 		
26
-		if($this->root == null)
26
+		if ($this->root == null)
27 27
 		{
28 28
 			$this->root = $node;
29 29
 			return $this;
30 30
 		}
31 31
 		
32 32
 		$n = $this->root;
33
-		while(1)
33
+		while (1)
34 34
 		{	
35
-			if($node->value < $n->value)
35
+			if ($node->value < $n->value)
36 36
 			{
37
-				if($n->left == null)
37
+				if ($n->left == null)
38 38
 				{
39 39
 					$n->left = $node;
40 40
 					return $this;
@@ -42,9 +42,9 @@  discard block
 block discarded – undo
42 42
 				
43 43
 				$n = $n->left;
44 44
 			}
45
-			else if($node->value > $n->value)
45
+			else if ($node->value > $n->value)
46 46
 			{
47
-				if($n->right == null)
47
+				if ($n->right == null)
48 48
 				{
49 49
 					$n->right = $node;
50 50
 					return $this;
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 				
53 53
 				$n = $n->right;
54 54
 			}
55
-			else if($node->value == $n->value) //node is already in the tree, we do not create duplicates!
55
+			else if ($node->value == $n->value) //node is already in the tree, we do not create duplicates!
56 56
 			{
57 57
 				return $this;
58 58
 			}
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	
67 67
 	public function traverse($order)
68 68
 	{
69
-		switch($order)
69
+		switch ($order)
70 70
 		{
71 71
 			case self::IN_ORDER:
72 72
 				//TODO
@@ -92,12 +92,12 @@  discard block
 block discarded – undo
92 92
 	
93 93
 	private function validate_parameter($node)
94 94
 	{
95
-		if(gettype($node) != "object")
95
+		if (gettype($node) != "object")
96 96
 		{
97 97
 			throw new UnexpectedType("Expected a Ptypes\TreeNode, got: " . gettype($node));
98 98
 		}
99 99
 		
100
-		if(get_class($node) != "Ptypes\TreeNode")
100
+		if (get_class($node) != "Ptypes\TreeNode")
101 101
 		{
102 102
 			throw new UnexpectedType("Expected a Ptypes\TreeNode, got: " . get_class($node));
103 103
 		}
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 		
32 32
 		$n = $this->root;
33 33
 		while(1)
34
-		{	
34
+		{
35 35
 			if($node->value < $n->value)
36 36
 			{
37 37
 				if($n->left == null)
@@ -52,10 +52,13 @@  discard block
 block discarded – undo
52 52
 				
53 53
 				$n = $n->right;
54 54
 			}
55
-			else if($node->value == $n->value) //node is already in the tree, we do not create duplicates!
55
+			else if($node->value == $n->value)
56
+			{
57
+				//node is already in the tree, we do not create duplicates!
56 58
 			{
57 59
 				return $this;
58 60
 			}
61
+			}
59 62
 		}
60 63
 	}
61 64
 	
Please login to merge, or discard this patch.