Completed
Push — master ( 08c634...f3919f )
by Tõnis
06:02 queued 03:07
created
MyArrayHelper.php 2 patches
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  * @package app\models\helpers
13 13
  * @author Tonis Ormisson <[email protected]>
14 14
  */
15
-class MyArrayHelper extends ArrayHelper{
15
+class MyArrayHelper extends ArrayHelper {
16 16
 
17 17
     /**
18 18
      * Take a non-indexed array and make an indexed array using the value 
@@ -22,13 +22,13 @@  discard block
 block discarded – undo
22 22
      * @throws InvalidArgumentException
23 23
      */
24 24
     public static function selfIndex($array) {
25
-        if(is_array($array)){
25
+        if (is_array($array)) {
26 26
             $out = [];
27 27
             foreach ($array as $value) {
28 28
                 $out[$value] = $value;
29 29
             }
30 30
             return $out;
31
-        }else{
31
+        }else {
32 32
             throw new InvalidArgumentException(gettype($array).' used as array in '.__CLASS__.'::'.__FUNCTION__);
33 33
         }
34 34
         
@@ -41,14 +41,14 @@  discard block
 block discarded – undo
41 41
      * @param array $array
42 42
      * @return array
43 43
      */
44
-    public static function mapIndex($map, $array){
45
-        if(is_array($array)){
44
+    public static function mapIndex($map, $array) {
45
+        if (is_array($array)) {
46 46
             $out = [];
47
-            foreach ($map as $key => $value){
47
+            foreach ($map as $key => $value) {
48 48
                 $out[$value] = $array[$key];
49 49
             }
50 50
             return $out;
51
-        }else{
51
+        }else {
52 52
             throw new InvalidArgumentException(gettype($array).' used as array in '.__CLASS__.'::'.__FUNCTION__);
53 53
         }
54 54
 
@@ -64,13 +64,13 @@  discard block
 block discarded – undo
64 64
      * @param integer $i
65 65
      * @return array
66 66
      */
67
-    public static function indexByRow($array, $i = 0){
67
+    public static function indexByRow($array, $i = 0) {
68 68
         $keys = $array[$i];
69
-        if(is_array($array) && !empty($array)){
70
-            $newArray= [];
69
+        if (is_array($array) && !empty($array)) {
70
+            $newArray = [];
71 71
             foreach ($array as $key=> $row) {
72 72
                 // don'd add the indexing element into output
73
-                if($key != $i){
73
+                if ($key != $i) {
74 74
                     $newRow = [];
75 75
                     $j = 0;
76 76
                     foreach ($row as $cell) {
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
             }
83 83
             
84 84
             return $newArray;
85
-        }else{
85
+        }else {
86 86
             throw new InvalidArgumentException(gettype($array).' used as array in '.__CLASS__.'::'.__FUNCTION__);
87 87
         }
88 88
 
@@ -95,21 +95,21 @@  discard block
 block discarded – undo
95 95
      * @param string $colName
96 96
      * @return array
97 97
      */
98
-    public static function indexByColumn($array, $colName){
99
-        if(is_array($array)){
100
-            if(!empty($array)){
101
-                $newArray= [];
98
+    public static function indexByColumn($array, $colName) {
99
+        if (is_array($array)) {
100
+            if (!empty($array)) {
101
+                $newArray = [];
102 102
                 foreach ($array as $key => $row) {
103
-                    if($row instanceof ActiveRecord){
103
+                    if ($row instanceof ActiveRecord) {
104 104
                         $rowArr = (array) $row->attributes;
105
-                    }else if(is_array($row)){
105
+                    }else if (is_array($row)) {
106 106
                         $rowArr = $row;
107
-                    }else{
107
+                    }else {
108 108
                         throw new InvalidArgumentException('Only arrays or ActiveRecord Objects can be used in '.__CLASS__.'::'.__FUNCTION__);
109 109
                     }
110 110
                     // make it array if input is object
111 111
 
112
-                    if(!isset($rowArr[$colName])){
112
+                    if (!isset($rowArr[$colName])) {
113 113
                         throw new InvalidArgumentException('"'.$colName.'" missing as key in '.__CLASS__.'::'.__FUNCTION__);
114 114
 
115 115
                     }
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
             }
120 120
             // do nothing, empty array
121 121
             return $array;
122
-        }else{
122
+        }else {
123 123
             throw new InvalidArgumentException(gettype($array).' used as array in '.__CLASS__.'::'.__FUNCTION__);
124 124
         }
125 125
     }
@@ -130,16 +130,16 @@  discard block
 block discarded – undo
130 130
      * @param mixed $removeValue value that we look for to delete
131 131
      * @return array
132 132
      */
133
-    public static function removeByValue($array,$removeValue,$column = false) {
133
+    public static function removeByValue($array, $removeValue, $column = false) {
134 134
         foreach ($array as $key =>$value) {
135 135
             // if column is set then remove by specific column value
136
-            if($column){
136
+            if ($column) {
137 137
 
138
-                if($value === $value[$column]){
138
+                if ($value === $value[$column]) {
139 139
                     unset($array[$key]);
140 140
                 }
141
-            }else{
142
-                if($value === $removeValue){
141
+            }else {
142
+                if ($value === $removeValue) {
143 143
                     unset($array[$key]);
144 144
                 }
145 145
             }
@@ -155,10 +155,10 @@  discard block
 block discarded – undo
155 155
      * @param string $value
156 156
      * @return ActiveRecord[]
157 157
      */
158
-    public static function removeModelByColumnValue($models, $attribute, $value){
159
-        if(!empty($models)){
160
-            foreach ($models as $key => $model){
161
-                if($model->{$attribute} === $value){
158
+    public static function removeModelByColumnValue($models, $attribute, $value) {
159
+        if (!empty($models)) {
160
+            foreach ($models as $key => $model) {
161
+                if ($model->{$attribute} === $value) {
162 162
                     unset($models[$key]);
163 163
                 }
164 164
             }
Please login to merge, or discard this patch.
Braces   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
                 $out[$value] = $value;
29 29
             }
30 30
             return $out;
31
-        }else{
31
+        } else{
32 32
             throw new InvalidArgumentException(gettype($array).' used as array in '.__CLASS__.'::'.__FUNCTION__);
33 33
         }
34 34
         
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
                 $out[$value] = $array[$key];
49 49
             }
50 50
             return $out;
51
-        }else{
51
+        } else{
52 52
             throw new InvalidArgumentException(gettype($array).' used as array in '.__CLASS__.'::'.__FUNCTION__);
53 53
         }
54 54
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
             }
83 83
             
84 84
             return $newArray;
85
-        }else{
85
+        } else{
86 86
             throw new InvalidArgumentException(gettype($array).' used as array in '.__CLASS__.'::'.__FUNCTION__);
87 87
         }
88 88
 
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
                 foreach ($array as $key => $row) {
103 103
                     if($row instanceof ActiveRecord){
104 104
                         $rowArr = (array) $row->attributes;
105
-                    }else if(is_array($row)){
105
+                    } else if(is_array($row)){
106 106
                         $rowArr = $row;
107
-                    }else{
107
+                    } else{
108 108
                         throw new InvalidArgumentException('Only arrays or ActiveRecord Objects can be used in '.__CLASS__.'::'.__FUNCTION__);
109 109
                     }
110 110
                     // make it array if input is object
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
             }
120 120
             // do nothing, empty array
121 121
             return $array;
122
-        }else{
122
+        } else{
123 123
             throw new InvalidArgumentException(gettype($array).' used as array in '.__CLASS__.'::'.__FUNCTION__);
124 124
         }
125 125
     }
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
                 if($value === $value[$column]){
139 139
                     unset($array[$key]);
140 140
                 }
141
-            }else{
141
+            } else{
142 142
                 if($value === $removeValue){
143 143
                     unset($array[$key]);
144 144
                 }
Please login to merge, or discard this patch.