@@ -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 | |
@@ -12,7 +12,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |