Passed
Push — master ( 7df88e...37e99a )
by Ruben
01:59
created
src/Matrix.php 2 patches
Braces   +24 added lines, -8 removed lines patch added patch discarded remove patch
@@ -24,10 +24,14 @@  discard block
 block discarded – undo
24 24
     public static function submatrix($matrix, $columns)
25 25
     {
26 26
         $n = count($matrix);
27
-        if ($n == 0) return [];
27
+        if ($n == 0) {
28
+            return [];
29
+        }
28 30
        
29 31
         $m = count($matrix[0]);
30
-        if ($m == 0) return $matrix;
32
+        if ($m == 0) {
33
+            return $matrix;
34
+        }
31 35
        
32 36
         $result = [];       
33 37
         for ($i=0; $i<$n; $i++) {
@@ -47,7 +51,9 @@  discard block
 block discarded – undo
47 51
     public static function toSquareMatrix($matrix, $ncol, $mcol, $vcol, $sparse = False)
48 52
     {
49 53
         $n = count($matrix);
50
-        if ($n == 0) return [];
54
+        if ($n == 0) {
55
+            return [];
56
+        }
51 57
         
52 58
         $labels = [];
53 59
         $id = 0;
@@ -64,7 +70,9 @@  discard block
 block discarded – undo
64 70
             $val = $matrix[$i][$vcol];
65 71
             $data[] = [$nid, $mid, $val];
66 72
         }
67
-        if ($sparse) return ["data" => $data, "labels" => $labels];
73
+        if ($sparse) {
74
+            return ["data" => $data, "labels" => $labels];
75
+        }
68 76
         $nlab = count($labels);
69 77
         $result = [];
70 78
         for ($i=0; $i<$nlab; $i++) {           
@@ -84,7 +92,9 @@  discard block
 block discarded – undo
84 92
     {
85 93
         $result = [];
86 94
         $n = count($matrix1);        
87
-        if ($n != count($matrix2)) throw new \Exception("Summing non compatible matrices. ");
95
+        if ($n != count($matrix2)) {
96
+            throw new \Exception("Summing non compatible matrices. ");
97
+        }
88 98
         $m = count($matrix1[0]);
89 99
         for ($i=0;$i<$n;$i++) {
90 100
             $tmp = [];
@@ -107,7 +117,9 @@  discard block
 block discarded – undo
107 117
         $n2 = count($matrix2);        
108 118
         $m2 = count($matrix2[0]);
109 119
         
110
-        if ($n2 !== $m1) throw new \Exception("Incompatible matrices: matrix1.columns != matrix2.rows");
120
+        if ($n2 !== $m1) {
121
+            throw new \Exception("Incompatible matrices: matrix1.columns != matrix2.rows");
122
+        }
111 123
 
112 124
         $result = [];
113 125
         for ($i=0; $i<$n1; $i++) {           
@@ -154,9 +166,13 @@  discard block
 block discarded – undo
154 166
      */
155 167
     public static function power($matrix, $n)
156 168
     {
157
-        if($n <= 1) return $matrix;        
169
+        if($n <= 1) {
170
+            return $matrix;
171
+        }
158 172
         $resp = self::multiply($matrix, $matrix);
159
-        if($n == 2) return $resp;
173
+        if($n == 2) {
174
+            return $resp;
175
+        }
160 176
         for($i=2; $i<$n; $i++) {
161 177
             $resp = self::multiply($resp, $matrix);
162 178
         }
Please login to merge, or discard this patch.
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
     {
85 85
         $resp = [];
86 86
         foreach ($matrix as $row) {
87
-           $resp[] = $row[$col];
87
+            $resp[] = $row[$col];
88 88
         }
89 89
         return $resp;
90 90
     }
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
         }
128 128
         for ($i=0; $i<$n1; $i++) {
129 129
             for ($j=0; $j<$m2; $j++) {
130
-                 for ($k=0; $k<$n2; $k++) {
131
-                     $result[$i][$j] += $matrix1[$i][$k]*$matrix2[$k][$j];
132
-                 }
130
+                    for ($k=0; $k<$n2; $k++) {
131
+                        $result[$i][$j] += $matrix1[$i][$k]*$matrix2[$k][$j];
132
+                    }
133 133
             }
134 134
         }        
135 135
         return $result;
Please login to merge, or discard this patch.
src/Persistence.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -179,7 +179,9 @@
 block discarded – undo
179 179
         $resp = [];
180 180
         foreach ($tests as $test) {
181 181
             $counts = self::getCountsById($pdo, $config, $test[0]);
182
-            if (count($counts) > 0) $resp[] = $counts;            
182
+            if (count($counts) > 0) {
183
+                $resp[] = $counts;
184
+            }
183 185
         }   
184 186
         return $resp;
185 187
     }
Please login to merge, or discard this patch.
src/SiteAnalyzer.php 1 patch
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -179,8 +179,7 @@  discard block
 block discarded – undo
179 179
         
180 180
         if (array_key_exists("level", $options)) {
181 181
             $level = $options["level"];
182
-        }
183
-        else {
182
+        } else {
184 183
             $level = count($labels) - 1;
185 184
         }
186 185
         
@@ -212,8 +211,7 @@  discard block
 block discarded – undo
212 211
         
213 212
         if (array_key_exists("level", $options)) {
214 213
             $level = $options["level"];
215
-        }
216
-        else {
214
+        } else {
217 215
             $level = count($labels) - 1;
218 216
         }
219 217
         
Please login to merge, or discard this patch.
src/ML.php 2 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -122,12 +122,12 @@
 block discarded – undo
122 122
      * @param
123 123
      */
124 124
     public static function eclideanDistance($p1, $p2) {
125
-       $len = count($p1);
126
-       $acum = 0;
127
-       for($i=0; $i<$len; $i++) {
128
-           $acum += ($p1[$i] - $p2[$i])**2;
129
-       }
130
-       return sqrt($acum);
125
+        $len = count($p1);
126
+        $acum = 0;
127
+        for($i=0; $i<$len; $i++) {
128
+            $acum += ($p1[$i] - $p2[$i])**2;
129
+        }
130
+        return sqrt($acum);
131 131
     }
132 132
     
133 133
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,9 @@
 block discarded – undo
31 31
         $niter = 0;
32 32
         $maxiter = 100;
33 33
         $npoints = count($data);
34
-        if ($npoints <= 0) throw new \Exception("Not enough data. ");    
34
+        if ($npoints <= 0) {
35
+            throw new \Exception("Not enough data. ");
36
+        }
35 37
         $ndimensions = count($data[0]);
36 38
         $centroids = [];
37 39
         for ($i=0;$i<$nclusters;$i++){
Please login to merge, or discard this patch.