@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * @package app\models\helpers |
14 | 14 | * @author Tonis Ormisson <[email protected]> |
15 | 15 | */ |
16 | -class MyArrayHelper extends ArrayHelper{ |
|
16 | +class MyArrayHelper extends ArrayHelper { |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * Take a non-indexed array and make an indexed array using the value |
@@ -23,13 +23,13 @@ discard block |
||
23 | 23 | * @throws InvalidParamException |
24 | 24 | */ |
25 | 25 | public static function selfIndex($array) { |
26 | - if(is_array($array)){ |
|
26 | + if (is_array($array)) { |
|
27 | 27 | $out = []; |
28 | 28 | foreach ($array as $value) { |
29 | 29 | $out[$value] = $value; |
30 | 30 | } |
31 | 31 | return $out; |
32 | - }else{ |
|
32 | + }else { |
|
33 | 33 | throw new InvalidParamException(gettype($array).' used as array in '.__CLASS__.'::'.__FUNCTION__); |
34 | 34 | } |
35 | 35 | |
@@ -42,14 +42,14 @@ discard block |
||
42 | 42 | * @param array $array |
43 | 43 | * @return array |
44 | 44 | */ |
45 | - public static function mapIndex($map, $array){ |
|
46 | - if(is_array($array)){ |
|
45 | + public static function mapIndex($map, $array) { |
|
46 | + if (is_array($array)) { |
|
47 | 47 | $out = []; |
48 | - foreach ($map as $key => $value){ |
|
48 | + foreach ($map as $key => $value) { |
|
49 | 49 | $out[$value] = $array[$key]; |
50 | 50 | } |
51 | 51 | return $out; |
52 | - }else{ |
|
52 | + }else { |
|
53 | 53 | throw new InvalidParamException(gettype($array).' used as array in '.__CLASS__.'::'.__FUNCTION__); |
54 | 54 | } |
55 | 55 | |
@@ -65,13 +65,13 @@ discard block |
||
65 | 65 | * @param integer $i |
66 | 66 | * @return array |
67 | 67 | */ |
68 | - public static function indexByRow($array, $i = 0){ |
|
68 | + public static function indexByRow($array, $i = 0) { |
|
69 | 69 | $keys = $array[$i]; |
70 | - if(is_array($array) && !empty($array)){ |
|
71 | - $newArray= []; |
|
70 | + if (is_array($array) && !empty($array)) { |
|
71 | + $newArray = []; |
|
72 | 72 | foreach ($array as $key=> $row) { |
73 | 73 | // don'd add the indexing element into output |
74 | - if($key != $i){ |
|
74 | + if ($key != $i) { |
|
75 | 75 | $newRow = []; |
76 | 76 | $j = 0; |
77 | 77 | foreach ($row as $cell) { |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | } |
84 | 84 | |
85 | 85 | return $newArray; |
86 | - }else{ |
|
86 | + }else { |
|
87 | 87 | throw new InvalidParamException(gettype($array).' used as array in '.__CLASS__.'::'.__FUNCTION__); |
88 | 88 | } |
89 | 89 | |
@@ -96,21 +96,21 @@ discard block |
||
96 | 96 | * @param string $colName |
97 | 97 | * @return array |
98 | 98 | */ |
99 | - public static function indexByColumn($array, $colName){ |
|
100 | - if(is_array($array)){ |
|
101 | - if(!empty($array)){ |
|
102 | - $newArray= []; |
|
99 | + public static function indexByColumn($array, $colName) { |
|
100 | + if (is_array($array)) { |
|
101 | + if (!empty($array)) { |
|
102 | + $newArray = []; |
|
103 | 103 | foreach ($array as $key => $row) { |
104 | - if($row instanceof ActiveRecord){ |
|
104 | + if ($row instanceof ActiveRecord) { |
|
105 | 105 | $rowArr = (array) $row->attributes; |
106 | - }else if(is_array($row)){ |
|
106 | + }else if (is_array($row)) { |
|
107 | 107 | $rowArr = $row; |
108 | - }else{ |
|
108 | + }else { |
|
109 | 109 | throw new InvalidParamException('Only arrays or ActiveRecord Objects can be used in '.__CLASS__.'::'.__FUNCTION__); |
110 | 110 | } |
111 | 111 | // make it array if input is object |
112 | 112 | |
113 | - if(!isset($rowArr[$colName])){ |
|
113 | + if (!isset($rowArr[$colName])) { |
|
114 | 114 | throw new InvalidParamException('"'.$colName.'" missing as key in '.__CLASS__.'::'.__FUNCTION__); |
115 | 115 | |
116 | 116 | } |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | } |
121 | 121 | // do nothing, empty array |
122 | 122 | return $array; |
123 | - }else{ |
|
123 | + }else { |
|
124 | 124 | throw new InvalidParamException(gettype($array).' used as array in '.__CLASS__.'::'.__FUNCTION__); |
125 | 125 | } |
126 | 126 | } |
@@ -131,16 +131,16 @@ discard block |
||
131 | 131 | * @param mixed $removeValue value that we look for to delete |
132 | 132 | * @return array |
133 | 133 | */ |
134 | - public static function removeByValue($array,$removeValue,$column = false) { |
|
134 | + public static function removeByValue($array, $removeValue, $column = false) { |
|
135 | 135 | foreach ($array as $key =>$value) { |
136 | 136 | // if column is set then remove by specific column value |
137 | - if($column){ |
|
137 | + if ($column) { |
|
138 | 138 | |
139 | - if($value === $value[$column]){ |
|
139 | + if ($value === $value[$column]) { |
|
140 | 140 | unset($array[$key]); |
141 | 141 | } |
142 | - }else{ |
|
143 | - if($value === $removeValue){ |
|
142 | + }else { |
|
143 | + if ($value === $removeValue) { |
|
144 | 144 | unset($array[$key]); |
145 | 145 | } |
146 | 146 | } |
@@ -156,10 +156,10 @@ discard block |
||
156 | 156 | * @param string $value |
157 | 157 | * @return ActiveRecord[] |
158 | 158 | */ |
159 | - public static function removeModelByColumnValue($models, $attribute, $value){ |
|
160 | - if(!empty($models)){ |
|
161 | - foreach ($models as $key => $model){ |
|
162 | - if($model->{$attribute} === $value){ |
|
159 | + public static function removeModelByColumnValue($models, $attribute, $value) { |
|
160 | + if (!empty($models)) { |
|
161 | + foreach ($models as $key => $model) { |
|
162 | + if ($model->{$attribute} === $value) { |
|
163 | 163 | unset($models[$key]); |
164 | 164 | } |
165 | 165 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | $out[$value] = $value; |
30 | 30 | } |
31 | 31 | return $out; |
32 | - }else{ |
|
32 | + } else{ |
|
33 | 33 | throw new InvalidParamException(gettype($array).' used as array in '.__CLASS__.'::'.__FUNCTION__); |
34 | 34 | } |
35 | 35 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | $out[$value] = $array[$key]; |
50 | 50 | } |
51 | 51 | return $out; |
52 | - }else{ |
|
52 | + } else{ |
|
53 | 53 | throw new InvalidParamException(gettype($array).' used as array in '.__CLASS__.'::'.__FUNCTION__); |
54 | 54 | } |
55 | 55 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | } |
84 | 84 | |
85 | 85 | return $newArray; |
86 | - }else{ |
|
86 | + } else{ |
|
87 | 87 | throw new InvalidParamException(gettype($array).' used as array in '.__CLASS__.'::'.__FUNCTION__); |
88 | 88 | } |
89 | 89 | |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | foreach ($array as $key => $row) { |
104 | 104 | if($row instanceof ActiveRecord){ |
105 | 105 | $rowArr = (array) $row->attributes; |
106 | - }else if(is_array($row)){ |
|
106 | + } else if(is_array($row)){ |
|
107 | 107 | $rowArr = $row; |
108 | - }else{ |
|
108 | + } else{ |
|
109 | 109 | throw new InvalidParamException('Only arrays or ActiveRecord Objects can be used in '.__CLASS__.'::'.__FUNCTION__); |
110 | 110 | } |
111 | 111 | // make it array if input is object |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | } |
121 | 121 | // do nothing, empty array |
122 | 122 | return $array; |
123 | - }else{ |
|
123 | + } else{ |
|
124 | 124 | throw new InvalidParamException(gettype($array).' used as array in '.__CLASS__.'::'.__FUNCTION__); |
125 | 125 | } |
126 | 126 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | if($value === $value[$column]){ |
140 | 140 | unset($array[$key]); |
141 | 141 | } |
142 | - }else{ |
|
142 | + } else{ |
|
143 | 143 | if($value === $removeValue){ |
144 | 144 | unset($array[$key]); |
145 | 145 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | const DEFAULT_PASSWORD_LENGTH = 9; |
11 | 11 | |
12 | 12 | |
13 | - public static function generatePassword($length=9, $strength=0) { |
|
13 | + public static function generatePassword($length = 9, $strength = 0) { |
|
14 | 14 | $vowels = 'aeuy'; |
15 | 15 | $consonants = 'bdghjmnpqrstvz'; |
16 | 16 | if ($strength & 1) { |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | if ($alt == 1) { |
33 | 33 | $password .= $consonants[(rand() % strlen($consonants))]; |
34 | 34 | $alt = 0; |
35 | - } else { |
|
35 | + }else { |
|
36 | 36 | $password .= $vowels[(rand() % strlen($vowels))]; |
37 | 37 | $alt = 1; |
38 | 38 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * get an uuid V4 |
45 | 45 | * @return string |
46 | 46 | */ |
47 | - public static function getUuidV4(){ |
|
47 | + public static function getUuidV4() { |
|
48 | 48 | $uuid = Uuid::uuid4(); |
49 | 49 | return $uuid->toString(); |
50 | 50 | } |
@@ -28,12 +28,12 @@ discard block |
||
28 | 28 | * Get current time in mysql datetime(6) format as "Y-m-d H:i:s.u" |
29 | 29 | * @return string |
30 | 30 | */ |
31 | - public function getDatetime6(){ |
|
31 | + public function getDatetime6() { |
|
32 | 32 | |
33 | 33 | // TODO this does now consider the getNow() |
34 | 34 | $t = microtime(true); |
35 | - $micro = sprintf("%06d",($t - floor($t)) * 1000000); |
|
36 | - $d = new DateTime( date('Y-m-d H:i:s.'.$micro, $t) ); |
|
35 | + $micro = sprintf("%06d", ($t - floor($t)) * 1000000); |
|
36 | + $d = new DateTime(date('Y-m-d H:i:s.'.$micro, $t)); |
|
37 | 37 | |
38 | 38 | return $d->format("Y-m-d H:i:s.u"); // note at point on "u" |
39 | 39 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * date where we will not reach. Typically default for time_closed value |
45 | 45 | * @return string |
46 | 46 | */ |
47 | - public function getEndOfTime(){ |
|
47 | + public function getEndOfTime() { |
|
48 | 48 | return self::END_OF_TIME; |
49 | 49 | } |
50 | 50 | |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | * @param string $datetime |
54 | 54 | * @return false|string |
55 | 55 | */ |
56 | - public function getMysqlDateTimeFromDateTime6 ($datetime) { |
|
57 | - return date("Y-m-d H:i:s", strtotime( $datetime )); |
|
56 | + public function getMysqlDateTimeFromDateTime6($datetime) { |
|
57 | + return date("Y-m-d H:i:s", strtotime($datetime)); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | |
@@ -63,16 +63,16 @@ discard block |
||
63 | 63 | * @return false|string |
64 | 64 | * @deprecated use Formatter |
65 | 65 | */ |
66 | - public function getDatetimeForDisplay($dateTime){ |
|
67 | - return date("Y-m-d H:i:s", strtotime( $dateTime )); |
|
66 | + public function getDatetimeForDisplay($dateTime) { |
|
67 | + return date("Y-m-d H:i:s", strtotime($dateTime)); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
71 | 71 | * @param string $sqlDate |
72 | 72 | * @return mixed |
73 | 73 | */ |
74 | - public function getDateDifferenceInDays($sqlDate){ |
|
75 | - $dStart = $this->now; |
|
74 | + public function getDateDifferenceInDays($sqlDate) { |
|
75 | + $dStart = $this->now; |
|
76 | 76 | $dEnd = new DateTime($sqlDate); |
77 | 77 | $dDiff = $dStart->diff($dEnd); |
78 | 78 | $days = $dDiff->days; |
@@ -13,7 +13,7 @@ |
||
13 | 13 | const TYPE_DATETIME = 'datetime'; |
14 | 14 | const TYPE_BOOLEAN = 'boolean'; |
15 | 15 | |
16 | - public static function getTypes(){ |
|
16 | + public static function getTypes() { |
|
17 | 17 | return [ |
18 | 18 | self::TYPE_STRING => 'String', |
19 | 19 | self::TYPE_INTEGER => 'Integer', |
@@ -17,12 +17,12 @@ discard block |
||
17 | 17 | */ |
18 | 18 | public static function replace($text, $params = []) { |
19 | 19 | $allParams = $params; |
20 | - return preg_replace_callback('/{([^}]+)}/', function ($m) use ($allParams) { |
|
20 | + return preg_replace_callback('/{([^}]+)}/', function($m) use ($allParams) { |
|
21 | 21 | // skip if is not set |
22 | - if(isset($allParams[$m[1]])){ |
|
22 | + if (isset($allParams[$m[1]])) { |
|
23 | 23 | return $allParams[$m[1]]; |
24 | 24 | } |
25 | - \Yii::error('Failed to replace field: '.$m[1] ,__METHOD__); |
|
25 | + \Yii::error('Failed to replace field: '.$m[1], __METHOD__); |
|
26 | 26 | return "{".$m[1]."}"; |
27 | 27 | }, $text); |
28 | 28 | } |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | * @param $text |
33 | 33 | * @return mixed |
34 | 34 | */ |
35 | - public static function getParams($text){ |
|
35 | + public static function getParams($text) { |
|
36 | 36 | preg_match_all('/{(.*?)}/', $text, $matches); |
37 | - if(is_array($matches)){ |
|
37 | + if (is_array($matches)) { |
|
38 | 38 | return $matches[0]; |
39 | 39 | } |
40 | 40 |