Passed
Branch master (c1fe78)
by Witali
02:25
created
src/Node.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -52,10 +52,10 @@  discard block
 block discarded – undo
52 52
         $this->totalScore = $totalScore;
53 53
     }
54 54
 
55
-    public function visit(){
55
+    public function visit() {
56 56
         $this->visited = true;
57 57
     }
58
-    public function close(){
58
+    public function close() {
59 59
         $this->closed = true;
60 60
     }
61 61
 
@@ -116,10 +116,10 @@  discard block
 block discarded – undo
116 116
         $this->guessedScore = $guessedScore;
117 117
     }
118 118
 
119
-    public function isClosed(){
119
+    public function isClosed() {
120 120
         return $this->closed === true;
121 121
     }
122
-    public function isVisited(){
122
+    public function isVisited() {
123 123
         return $this->visited === true;
124 124
     }
125 125
 }
Please login to merge, or discard this patch.
src/Astar.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
         $heap->insert($start);
47 47
 
48 48
         $current = $this->fillHeap($heap, $start, $end);
49
-        if($current !== $end){
49
+        if ($current !== $end) {
50 50
             return [];
51 51
         }
52 52
         return $this->getReversedPath($current);
@@ -73,14 +73,14 @@  discard block
 block discarded – undo
73 73
                 if ($neighbor->isClosed() || in_array($neighbor->getCosts(), $this->blocked)) {
74 74
                     continue;
75 75
                 }
76
-                $score = $current->getScore() + $neighbor->getCosts();
76
+                $score = $current->getScore()+$neighbor->getCosts();
77 77
                 $visited = $neighbor->isVisited();
78 78
                 if (!$visited || $score < $neighbor->getScore()) {
79 79
                     $neighbor->visit();
80 80
                     $neighbor->setParent($current);
81 81
                     $neighbor->setGuessedScore($this->heuristic->compare($neighbor, $end));
82 82
                     $neighbor->setScore($score);
83
-                    $neighbor->setTotalScore($neighbor->getScore() + $neighbor->getGuessedScore());
83
+                    $neighbor->setTotalScore($neighbor->getScore()+$neighbor->getGuessedScore());
84 84
                     if (!$visited) {
85 85
                         $heap->insert($neighbor);
86 86
                     }
Please login to merge, or discard this patch.
src/Heuristic/Diagonal.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -5,10 +5,10 @@
 block discarded – undo
5 5
 
6 6
 class Diagonal implements HeuristicInterface{
7 7
 
8
-     public function compare(Node $node, Node $goal) {
8
+        public function compare(Node $node, Node $goal) {
9 9
 
10
-         $deltaX = abs($node->getX() - $goal->getX());
11
-         $deltaY = abs($node->getY() - $goal->getY());
10
+            $deltaX = abs($node->getX() - $goal->getX());
11
+            $deltaY = abs($node->getY() - $goal->getY());
12 12
         return max($deltaX,$deltaY);
13 13
     }
14 14
 
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -3,13 +3,13 @@
 block discarded – undo
3 3
 use BlackScorp\Astar\HeuristicInterface;
4 4
 use BlackScorp\Astar\Node;
5 5
 
6
-class Diagonal implements HeuristicInterface{
6
+class Diagonal implements HeuristicInterface {
7 7
 
8 8
      public function compare(Node $node, Node $goal) {
9 9
 
10
-         $deltaX = abs($node->getX() - $goal->getX());
11
-         $deltaY = abs($node->getY() - $goal->getY());
12
-        return max($deltaX,$deltaY);
10
+         $deltaX = abs($node->getX()-$goal->getX());
11
+         $deltaY = abs($node->getY()-$goal->getY());
12
+        return max($deltaX, $deltaY);
13 13
     }
14 14
 
15 15
 }
Please login to merge, or discard this patch.
src/Heuristic/Euclidean.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -3,13 +3,13 @@
 block discarded – undo
3 3
 use BlackScorp\Astar\HeuristicInterface;
4 4
 use BlackScorp\Astar\Node;
5 5
 
6
-class Euclidean implements HeuristicInterface{
6
+class Euclidean implements HeuristicInterface {
7 7
 
8 8
     public function compare(Node $node, Node $goal) {
9 9
   
10
-        $deltaX = abs($node->getX() - $goal->getX());
11
-        $deltaY = abs($node->getY() - $goal->getY());
12
-        return sqrt($deltaX * $deltaX + $deltaY * $deltaY);
10
+        $deltaX = abs($node->getX()-$goal->getX());
11
+        $deltaY = abs($node->getY()-$goal->getY());
12
+        return sqrt($deltaX * $deltaX+$deltaY * $deltaY);
13 13
     }
14 14
 
15 15
 }
Please login to merge, or discard this patch.
src/Heuristic/Manhattan.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -3,13 +3,13 @@
 block discarded – undo
3 3
 use BlackScorp\Astar\HeuristicInterface;
4 4
 use BlackScorp\Astar\Node;
5 5
 
6
-class Manhattan implements HeuristicInterface{
6
+class Manhattan implements HeuristicInterface {
7 7
 
8 8
     public function compare(Node $node, Node $goal) {
9 9
   
10
-        $deltaX = abs($node->getX() - $goal->getX());
11
-        $deltaY = abs($node->getY() - $goal->getY());
12
-        return $deltaX + $deltaY;
10
+        $deltaX = abs($node->getX()-$goal->getX());
11
+        $deltaY = abs($node->getY()-$goal->getY());
12
+        return $deltaX+$deltaY;
13 13
     }
14 14
 
15 15
 }
Please login to merge, or discard this patch.
src/ScoreHeap.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
     {
13 13
 
14 14
         if($value1->getTotalScore() === $value2->getTotalScore()) return 0;
15
-       return ($value1->getTotalScore() < $value2->getTotalScore())? 1 : -1 ;
15
+        return ($value1->getTotalScore() < $value2->getTotalScore())? 1 : -1 ;
16 16
     }
17 17
 
18 18
 }
19 19
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -2,17 +2,17 @@
 block discarded – undo
2 2
 namespace BlackScorp\Astar;
3 3
 
4 4
 
5
-class ScoreHeap extends \SplHeap{
5
+class ScoreHeap extends \SplHeap {
6 6
     /**
7 7
      * @param Node $value1
8 8
      * @param Node $value2
9 9
      * @return int
10 10
      */
11
-    protected function compare($value1,$value2)
11
+    protected function compare($value1, $value2)
12 12
     {
13 13
 
14
-        if($value1->getTotalScore() === $value2->getTotalScore()) return 0;
15
-       return ($value1->getTotalScore() < $value2->getTotalScore())? 1 : -1 ;
14
+        if ($value1->getTotalScore() === $value2->getTotalScore()) return 0;
15
+       return ($value1->getTotalScore() < $value2->getTotalScore()) ? 1 : -1;
16 16
     }
17 17
 
18 18
 }
19 19
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,9 @@
 block discarded – undo
11 11
     protected function compare($value1,$value2)
12 12
     {
13 13
 
14
-        if($value1->getTotalScore() === $value2->getTotalScore()) return 0;
14
+        if($value1->getTotalScore() === $value2->getTotalScore()) {
15
+            return 0;
16
+        }
15 17
        return ($value1->getTotalScore() < $value2->getTotalScore())? 1 : -1 ;
16 18
     }
17 19
 
Please login to merge, or discard this patch.
src/Grid.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
      */
24 24
     public function getPoint($y, $x)
25 25
     {
26
-        return isset($this->nodes[$y][$x])?$this->nodes[$y][$x]:false;
26
+        return isset($this->nodes[$y][$x]) ? $this->nodes[$y][$x] : false;
27 27
     }
28 28
 
29 29
     /**
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
         $y = $node->getY();
39 39
 
40 40
         $neighbourLocations = [
41
-            [$y -1,$x],
42
-            [$y +1,$x],
43
-            [$y,$x-1],
44
-            [$y,$x+1]
41
+            [$y-1, $x],
42
+            [$y+1, $x],
43
+            [$y, $x-1],
44
+            [$y, $x+1]
45 45
         ];
46
-        if($diagonal){
47
-            $neighbourLocations[]=[$y-1,$x-1];
48
-            $neighbourLocations[]=[$y+1,$x-1];
49
-            $neighbourLocations[]=[$y-1,$x+1];
50
-            $neighbourLocations[]=[$y+1,$x+1];
46
+        if ($diagonal) {
47
+            $neighbourLocations[] = [$y-1, $x-1];
48
+            $neighbourLocations[] = [$y+1, $x-1];
49
+            $neighbourLocations[] = [$y-1, $x+1];
50
+            $neighbourLocations[] = [$y+1, $x+1];
51 51
         }
52
-        foreach($neighbourLocations as $location){
53
-            list($y,$x) = $location;
54
-            $node = $this->getPoint($y,$x);
55
-            if($node){
56
-                $result[]=$node;
52
+        foreach ($neighbourLocations as $location) {
53
+            list($y, $x) = $location;
54
+            $node = $this->getPoint($y, $x);
55
+            if ($node) {
56
+                $result[] = $node;
57 57
             }
58 58
 
59 59
         }
Please login to merge, or discard this patch.