CoreLibs Array keyword remove and switch over to []

This commit is contained in:
Clemens Schwaighofer
2021-06-30 15:07:22 +09:00
parent 76e0c0ac06
commit 678aa7460e
17 changed files with 57 additions and 46 deletions

View File

@@ -1,4 +1,5 @@
<?php declare(strict_types=1); <?php // phpcs:ignore warning
declare(strict_types=1);
/******************************************************************** /********************************************************************
* AUTHOR: Clemens Schwaighofer * AUTHOR: Clemens Schwaighofer
* CREATED: 2018/10/11 * CREATED: 2018/10/11

View File

@@ -81,8 +81,8 @@ if (!$login->login) {
// can be overridden when setting DEBUG_ALL_OVERRIDE on top of the script (for emergency debugging of one page only) // can be overridden when setting DEBUG_ALL_OVERRIDE on top of the script (for emergency debugging of one page only)
if ((TARGET == 'live' || TARGET == 'remote') && !$DEBUG_ALL_OVERRIDE) { if ((TARGET == 'live' || TARGET == 'remote') && !$DEBUG_ALL_OVERRIDE) {
foreach (['debug', 'echo', 'print'] as $target) { foreach (['debug', 'echo', 'print'] as $target) {
$login->log->setLogLevelAll($type, false); $login->log->setLogLevelAll($target, false);
$cms->log->setLogLevelAll($type, false); $cms->log->setLogLevelAll($target, false);
} }
} }
$smarty->DATA['JS_DEBUG'] = DEBUG; $smarty->DATA['JS_DEBUG'] = DEBUG;

View File

@@ -646,7 +646,7 @@ class Basic
/** /**
* array search simple. looks for key, value Combined, if found, returns true * array search simple. looks for key, value Combined, if found, returns true
* @param array $array array(search in) * @param array $array array (search in)
* @param string|int $key key (key to search in) * @param string|int $key key (key to search in)
* @param string|int $value value (what to find) * @param string|int $value value (what to find)
* @return bool true on found, false on not found * @return bool true on found, false on not found
@@ -731,7 +731,7 @@ class Basic
{ {
trigger_error('Method '.__METHOD__.' is deprecated, use join()', E_USER_DEPRECATED); trigger_error('Method '.__METHOD__.' is deprecated, use join()', E_USER_DEPRECATED);
if (!is_array($array)) { if (!is_array($array)) {
$array = array(); $array = [];
} }
return join($connect_char, $array); return join($connect_char, $array);
} }
@@ -755,7 +755,7 @@ class Basic
* @return array flattened keys array * @return array flattened keys array
* @deprecated Use \CoreLibs\Combined\ArrayHandler::flattenArrayKey() instead * @deprecated Use \CoreLibs\Combined\ArrayHandler::flattenArrayKey() instead
*/ */
public static function flattenArrayKey(array $array/*, array $return = array()*/): array public static function flattenArrayKey(array $array/*, array $return = []*/): array
{ {
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Combined\ArrayHandler::flattenArrayKey()', E_USER_DEPRECATED); trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Combined\ArrayHandler::flattenArrayKey()', E_USER_DEPRECATED);
return \CoreLibs\Combined\ArrayHandler::flattenArrayKey($array); return \CoreLibs\Combined\ArrayHandler::flattenArrayKey($array);
@@ -764,7 +764,7 @@ class Basic
/** /**
* searches for key -> value in an array tree and writes the value one level up * searches for key -> value in an array tree and writes the value one level up
* this will remove this leaf will all other values * this will remove this leaf will all other values
* @param array $array array(nested) * @param array $array array (nested)
* @param string|int $search key to find that has no sub leaf and will be pushed up * @param string|int $search key to find that has no sub leaf and will be pushed up
* @return array modified, flattened array * @return array modified, flattened array
* @deprecated Use \CoreLibs\Combined\ArrayHandler::arrayFlatForKey() instead * @deprecated Use \CoreLibs\Combined\ArrayHandler::arrayFlatForKey() instead
@@ -1229,9 +1229,9 @@ class Basic
{ {
trigger_error('Method '.__METHOD__.' has been removed', E_USER_DEPRECATED); trigger_error('Method '.__METHOD__.' has been removed', E_USER_DEPRECATED);
/* // set default password cost: use default set automatically /* // set default password cost: use default set automatically
$this->password_options = array( $this->password_options = [
// 'cost' => PASSWORD_BCRYPT_DEFAULT_COST // 'cost' => PASSWORD_BCRYPT_DEFAULT_COST
); */ ]; */
} }
/** /**

View File

@@ -122,7 +122,7 @@ class ArrayHandler
/** /**
* array search simple. looks for key, value combination, if found, returns true * array search simple. looks for key, value combination, if found, returns true
* @param array $array array(search in) * @param array $array search in as array
* @param string|int $key key (key to search in) * @param string|int $key key (key to search in)
* @param string|int $value value (what to find) * @param string|int $value value (what to find)
* @return bool true on found, false on not found * @return bool true on found, false on not found
@@ -313,7 +313,7 @@ class ArrayHandler
/** /**
* searches for key -> value in an array tree and writes the value one level up * searches for key -> value in an array tree and writes the value one level up
* this will remove this leaf will all other values * this will remove this leaf will all other values
* @param array $array array(nested) * @param array $array nested array
* @param string|int $search key to find that has no sub leaf and will be pushed up * @param string|int $search key to find that has no sub leaf and will be pushed up
* @return array modified, flattened array * @return array modified, flattened array
*/ */

View File

@@ -190,8 +190,8 @@ class DateTime
list ($start_year, $start_month, $start_day) = array_pad(preg_split('/[\/-]/', $start_date), 3, null); list ($start_year, $start_month, $start_day) = array_pad(preg_split('/[\/-]/', $start_date), 3, null);
list ($end_year, $end_month, $end_day) = array_pad(preg_split('/[\/-]/', $end_date), 3, null); list ($end_year, $end_month, $end_day) = array_pad(preg_split('/[\/-]/', $end_date), 3, null);
// check that month & day are two digits and then combine // check that month & day are two digits and then combine
foreach (array('start', 'end') as $prefix) { foreach (['start', 'end'] as $prefix) {
foreach (array('month', 'day') as $date_part) { foreach (['month', 'day'] as $date_part) {
$_date = $prefix.'_'.$date_part; $_date = $prefix.'_'.$date_part;
if (isset($$_date) && $$_date < 10 && !preg_match("/^0/", $$_date)) { if (isset($$_date) && $$_date < 10 && !preg_match("/^0/", $$_date)) {
$$_date = '0'.$$_date; $$_date = '0'.$$_date;
@@ -199,7 +199,7 @@ class DateTime
} }
$_date = $prefix.'_date'; $_date = $prefix.'_date';
$$_date = ''; $$_date = '';
foreach (array('year', 'month', 'day') as $date_part) { foreach (['year', 'month', 'day'] as $date_part) {
$_sub_date = $prefix.'_'.$date_part; $_sub_date = $prefix.'_'.$date_part;
$$_date .= $$_sub_date; $$_date .= $$_sub_date;
} }
@@ -254,7 +254,7 @@ class DateTime
public static function calcDaysInterval($start_date, $end_date, bool $return_named = false): array public static function calcDaysInterval($start_date, $end_date, bool $return_named = false): array
{ {
// pos 0 all, pos 1 weekday, pos 2 weekend // pos 0 all, pos 1 weekday, pos 2 weekend
$days = array(); $days = [];
$start = new \DateTime($start_date); $start = new \DateTime($start_date);
$end = new \DateTime($end_date); $end = new \DateTime($end_date);
// so we include the last day too, we need to add +1 second in the time // so we include the last day too, we need to add +1 second in the time
@@ -275,11 +275,11 @@ class DateTime
} }
} }
if ($return_named === true) { if ($return_named === true) {
return array( return [
'overall' => $days[0], 'overall' => $days[0],
'weekday' => $days[1], 'weekday' => $days[1],
'weekend' => $days[2] 'weekend' => $days[2]
); ];
} else { } else {
return $days; return $days;
} }

View File

@@ -65,7 +65,7 @@ class Byte
return $bytes.'B'; return $bytes.'B';
} }
// labels in order of size [Y, Z] // labels in order of size [Y, Z]
$labels = array('', 'K', 'M', 'G', 'T', 'P', 'E'); $labels = ['', 'K', 'M', 'G', 'T', 'P', 'E'];
// exp position calculation // exp position calculation
$exp = floor(log($abs_bytes, $unit)); $exp = floor(log($abs_bytes, $unit));
// avoid printing out anything larger than max labels // avoid printing out anything larger than max labels

View File

@@ -24,7 +24,7 @@ class Colors
public static function hex2rgb(string $hexStr, bool $returnAsString = false, string $seperator = ',') public static function hex2rgb(string $hexStr, bool $returnAsString = false, string $seperator = ',')
{ {
$hexStr = preg_replace("/[^0-9A-Fa-f]/", '', $hexStr); // Gets a proper hex string $hexStr = preg_replace("/[^0-9A-Fa-f]/", '', $hexStr); // Gets a proper hex string
$rgbArray = array(); $rgbArray = [];
if (strlen($hexStr) == 6) { if (strlen($hexStr) == 6) {
// If a proper hex code, convert using bitwise operation. No overhead... faster // If a proper hex code, convert using bitwise operation. No overhead... faster
$colorVal = hexdec($hexStr); $colorVal = hexdec($hexStr);
@@ -59,7 +59,7 @@ class Colors
if ($hex_prefix === true) { if ($hex_prefix === true) {
$hex_color = '#'; $hex_color = '#';
} }
foreach (array('red', 'green', 'blue') as $color) { foreach (['red', 'green', 'blue'] as $color) {
// if not valid, set to gray // if not valid, set to gray
if ($$color < 0 || $$color > 255) { if ($$color < 0 || $$color > 255) {
$$color = 125; $$color = 125;
@@ -82,7 +82,7 @@ class Colors
public static function rgb2hsb(int $red, int $green, int $blue): array public static function rgb2hsb(int $red, int $green, int $blue): array
{ {
// check that rgb is from 0 to 255 // check that rgb is from 0 to 255
foreach (array('red', 'green', 'blue') as $c) { foreach (['red', 'green', 'blue'] as $c) {
if ($$c < 0 || $$c > 255) { if ($$c < 0 || $$c > 255) {
$$c = 0; $$c = 0;
} }
@@ -94,7 +94,7 @@ class Colors
$HUE = 0; $HUE = 0;
if ($MAX == $MIN) { if ($MAX == $MIN) {
return array(0, 0, round($MAX * 100)); return [0, 0, round($MAX * 100)];
} }
if ($red == $MAX) { if ($red == $MAX) {
$HUE = ($green - $blue) / ($MAX - $MIN); $HUE = ($green - $blue) / ($MAX - $MIN);
@@ -108,11 +108,11 @@ class Colors
$HUE += 360; $HUE += 360;
} }
return array( return [
(int)round($HUE), (int)round($HUE),
(int)round((($MAX - $MIN) / $MAX) * 100), (int)round((($MAX - $MIN) / $MAX) * 100),
(int)round($MAX * 100) (int)round($MAX * 100)
); ];
} }
/** /**
@@ -140,7 +140,7 @@ class Colors
$V /= 100; $V /= 100;
if ($S == 0) { if ($S == 0) {
return array($V * 255, $V * 255, $V * 255); return [$V * 255, $V * 255, $V * 255];
} }
$Hi = floor($H / 60); $Hi = floor($H / 60);
@@ -186,11 +186,11 @@ class Colors
$blue = 0; $blue = 0;
} }
return array( return [
(int)round($red * 255), (int)round($red * 255),
(int)round($green * 255), (int)round($green * 255),
(int)round($blue * 255) (int)round($blue * 255)
); ];
} }
/** /**
@@ -205,7 +205,7 @@ class Colors
public static function rgb2hsl(int $red, int $green, int $blue): array public static function rgb2hsl(int $red, int $green, int $blue): array
{ {
// check that rgb is from 0 to 255 // check that rgb is from 0 to 255
foreach (array('red', 'green', 'blue') as $c) { foreach (['red', 'green', 'blue'] as $c) {
if ($$c < 0 || $$c > 255) { if ($$c < 0 || $$c > 255) {
$$c = 0; $$c = 0;
} }
@@ -270,7 +270,7 @@ class Colors
$lum /= 100; $lum /= 100;
// if saturation is 0 // if saturation is 0
if ($sat == 0) { if ($sat == 0) {
return array($lum * 255, $lum * 255, $lum * 255); return [$lum * 255, $lum * 255, $lum * 255];
} else { } else {
$m2 = $lum < 0.5 ? $lum * ($sat + 1) : ($lum + $sat) - ($lum * $sat); $m2 = $lum < 0.5 ? $lum * ($sat + 1) : ($lum + $sat) - ($lum * $sat);
$m1 = $lum * 2 - $m2; $m1 = $lum * 2 - $m2;
@@ -292,11 +292,11 @@ class Colors
return $m1; return $m1;
}; };
return array( return [
(int)round(255 * $hueue($hue + (1 / 3))), (int)round(255 * $hueue($hue + (1 / 3))),
(int)round(255 * $hueue($hue)), (int)round(255 * $hueue($hue)),
(int)round(255 * $hueue($hue - (1 / 3))) (int)round(255 * $hueue($hue - (1 / 3)))
); ];
} }
} }
} }

View File

@@ -30,7 +30,7 @@ class Html
*/ */
public static function removeLB(string $string, string $replace = ' '): string public static function removeLB(string $string, string $replace = ' '): string
{ {
return str_replace(array("\r", "\n"), $replace, $string); return str_replace(["\r", "\n"], $replace, $string);
} }
/** /**

View File

@@ -6,7 +6,7 @@
* RELEASED LICENSE: GNU GPL 3 * RELEASED LICENSE: GNU GPL 3
* SHORT DESC :RIPTION: * SHORT DESC :RIPTION:
* DB Array IO Class: * DB Array IO Class:
* writes, reads or deletes a complete array(one data set) in/out a * writes, reads or deletes a complete array (one data set) in/out a
* table from the connected DB. * table from the connected DB.
* you don't have to write any SQL queries, worry over update/insert * you don't have to write any SQL queries, worry over update/insert
* *

View File

@@ -41,7 +41,7 @@
* $class_name * $class_name
* - the name of the class * - the name of the class
* $class_version * $class_version
* - the version as an array(major, minor, patchlvl, daypatch) * - the version as an array [major, minor, patchlvl, daypatch]
* $class_last_changed * $class_last_changed
* - date (mysql format) for the last change * - date (mysql format) for the last change
* $class_created * $class_created
@@ -147,7 +147,7 @@
* _db_error() * _db_error()
* - INTERNAL ONLY!! error that occured during execution * - INTERNAL ONLY!! error that occured during execution
* $string _print_array($array) * $string _print_array($array)
* - returns string of an array(only for interal use) * - returns string of an array (only for interal use)
* 1/0 _connect_to_db() * 1/0 _connect_to_db()
* - returns 1 for successfull DB connection or 0 for none * - returns 1 for successfull DB connection or 0 for none
* 1/0 _check_query_for_select($query) * 1/0 _check_query_for_select($query)
@@ -643,7 +643,7 @@ class IO extends \CoreLibs\Basic
} else { } else {
preg_match("/(INSERT INTO|DELETE FROM|UPDATE) (([\w_]+)\.)?([\w_]+) /i", $query, $matches); preg_match("/(INSERT INTO|DELETE FROM|UPDATE) (([\w_]+)\.)?([\w_]+) /i", $query, $matches);
} }
return array($matches[3], $matches[4]); return [$matches[3], $matches[4]];
} }
/** /**
@@ -1871,7 +1871,7 @@ class IO extends \CoreLibs\Basic
* writes into one table based on array of table columns * writes into one table based on array of table columns
* PARAM INFO: $primary key * PARAM INFO: $primary key
* this can be a plain string/int and will be internal transformed into the array form * this can be a plain string/int and will be internal transformed into the array form
* or it takes the array form of array(row => column, value => pk value) * or it takes the array form of array [row => column, value => pk value]
* @param array $write_array list of elements to write * @param array $write_array list of elements to write
* @param int|string|array $primary_key primary key string or array set * @param int|string|array $primary_key primary key string or array set
* @param string $table name for the target table * @param string $table name for the target table

View File

@@ -569,6 +569,16 @@ class Logging
unset($this->error_msg[$level]); unset($this->error_msg[$level]);
} }
} }
/**
* Get current error message array
*
* @return array error messages collected
*/
public function getErrorMsg(): array
{
return $this->error_msg;
}
} }
// __END__ // __END__

View File

@@ -50,7 +50,7 @@ class GetTextReader
private $total = 0; // total string count private $total = 0; // total string count
private $table_originals = null; // table for original strings (offsets) private $table_originals = null; // table for original strings (offsets)
private $table_translations = null; // table for translated strings (offsets) private $table_translations = null; // table for translated strings (offsets)
private $cache_translations = array(); // original -> translation mapping private $cache_translations = []; // original -> translation mapping
/* Methods */ /* Methods */
@@ -166,7 +166,7 @@ class GetTextReader
} }
if ($this->enable_cache) { if ($this->enable_cache) {
$this->cache_translations = array(); $this->cache_translations = [];
/* read all strings in the cache */ /* read all strings in the cache */
for ($i = 0; $i < $this->total; $i++) { for ($i = 0; $i < $this->total; $i++) {
$this->STREAM->seekto($this->table_originals[$i * 2 + 2]); $this->STREAM->seekto($this->table_originals[$i * 2 + 2]);

View File

@@ -89,7 +89,7 @@ class Encoding
$compare = mb_convert_encoding($temp, $from_encoding, $to_encoding); $compare = mb_convert_encoding($temp, $from_encoding, $to_encoding);
// if string does not match anymore we have a convert problem // if string does not match anymore we have a convert problem
if ($string != $compare) { if ($string != $compare) {
$failed = array(); $failed = [];
// go through each character and find the ones that do not match // go through each character and find the ones that do not match
for ($i = 0, $iMax = mb_strlen($string, $from_encoding); $i < $iMax; $i ++) { for ($i = 0, $iMax = mb_strlen($string, $from_encoding); $i < $iMax; $i ++) {
$char = mb_substr($string, $i, 1, $from_encoding); $char = mb_substr($string, $i, 1, $from_encoding);

View File

@@ -121,7 +121,7 @@ class Elements
public static function magicLinks(string $string, string $target = "_blank"): string public static function magicLinks(string $string, string $target = "_blank"): string
{ {
$output = $string; $output = $string;
$protList = array("http", "https", "ftp", "news", "nntp"); $protList = ["http", "https", "ftp", "news", "nntp"];
// find urls w/o protocol // find urls w/o protocol
$output = preg_replace("/([^\/])www\.([\w\.-]+)\.([a-zA-Z]{2,4})/", "\\1http://www.\\2.\\3", $output); $output = preg_replace("/([^\/])www\.([\w\.-]+)\.([a-zA-Z]{2,4})/", "\\1http://www.\\2.\\3", $output);

View File

@@ -1516,7 +1516,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
// echo "PK NAME: ".$this->pk_name."/".$this->int_pk_name.": ".$this->table_array[$this->pk_name]['value']."/".$this->table_array[$this->int_pk_name]['value']."<br>"; // echo "PK NAME: ".$this->pk_name."/".$this->int_pk_name.": ".$this->table_array[$this->pk_name]['value']."/".$this->table_array[$this->int_pk_name]['value']."<br>";
// write the object // write the object
$this->dbWrite($addslashes); $this->dbWrite($addslashes);
// write reference array(s) if necessary // write reference array (s) if necessary
if (is_array($this->reference_array)) { if (is_array($this->reference_array)) {
if (!is_array($this->reference_array)) { if (!is_array($this->reference_array)) {
$this->reference_array = []; $this->reference_array = [];

View File

@@ -29,11 +29,11 @@ class Image
bool $clear_cache = false bool $clear_cache = false
) { ) {
// get image type flags // get image type flags
$image_types = array( $image_types = [
1 => 'gif', 1 => 'gif',
2 => 'jpg', 2 => 'jpg',
3 => 'png' 3 => 'png'
); ];
$return_data = false; $return_data = false;
$CONVERT = ''; $CONVERT = '';
// if CONVERT is not defined, abort // if CONVERT is not defined, abort

View File

@@ -34,7 +34,7 @@ function MyErrorHandler(int $type, string $message, string $file, int $line, arr
return false; return false;
} }
// ERROR LEVEL // ERROR LEVEL
$error_level = array( $error_level = [
1 => 'E_ERROR', 1 => 'E_ERROR',
2 => 'E_WARNING', 2 => 'E_WARNING',
4 => 'E_PARSE', 4 => 'E_PARSE',
@@ -51,7 +51,7 @@ function MyErrorHandler(int $type, string $message, string $file, int $line, arr
8192 => 'E_DEPRICATED', 8192 => 'E_DEPRICATED',
16384 => 'E_USER_DEPRICATED', 16384 => 'E_USER_DEPRICATED',
30719 => 'E_ALL' 30719 => 'E_ALL'
); ];
// get the current page name (strip path) // get the current page name (strip path)
$page_temp = explode(DIRECTORY_SEPARATOR, $_SERVER["PHP_SELF"]); $page_temp = explode(DIRECTORY_SEPARATOR, $_SERVER["PHP_SELF"]);