Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4adb9fba30 | ||
|
|
672931ee67 | ||
|
|
373a9aff2f | ||
|
|
4e3ceecac8 | ||
|
|
8bf694b2b2 |
43
.eslintrc.js
Normal file
43
.eslintrc.js
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
module.exports = {
|
||||||
|
'env': {
|
||||||
|
'browser': true,
|
||||||
|
'es6': true,
|
||||||
|
'commonjs': true,
|
||||||
|
'jquery': true
|
||||||
|
},
|
||||||
|
'extends': 'eslint:recommended',
|
||||||
|
'parserOptions': {
|
||||||
|
'ecmaVersion': 6
|
||||||
|
},
|
||||||
|
'rules': {
|
||||||
|
'indent': [
|
||||||
|
'error',
|
||||||
|
'tab',
|
||||||
|
{
|
||||||
|
'SwitchCase': 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'linebreak-style': [
|
||||||
|
'error',
|
||||||
|
'unix'
|
||||||
|
],
|
||||||
|
'quotes': [
|
||||||
|
'error',
|
||||||
|
'single'
|
||||||
|
],
|
||||||
|
'semi': [
|
||||||
|
'error',
|
||||||
|
'always'
|
||||||
|
],
|
||||||
|
'no-console': 'off',
|
||||||
|
'no-unused-vars': [
|
||||||
|
'error', {
|
||||||
|
'vars': 'all',
|
||||||
|
'args': 'after-used',
|
||||||
|
'ignoreRestSiblings': false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
// Requires eslint >= v8.14.0
|
||||||
|
'no-constant-binary-expression': 'error'
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -3,10 +3,10 @@
|
|||||||
<phar name="phpunit" version="^9.6" installed="9.6.13" location="./tools/phpunit" copy="false"/>
|
<phar name="phpunit" version="^9.6" installed="9.6.13" location="./tools/phpunit" copy="false"/>
|
||||||
<phar name="phpcbf" version="^3.7.2" installed="3.7.2" location="./tools/phpcbf" copy="false"/>
|
<phar name="phpcbf" version="^3.7.2" installed="3.7.2" location="./tools/phpcbf" copy="false"/>
|
||||||
<phar name="phpcs" version="^3.7.2" installed="3.7.2" location="./tools/phpcs" copy="false"/>
|
<phar name="phpcs" version="^3.7.2" installed="3.7.2" location="./tools/phpcs" copy="false"/>
|
||||||
<phar name="phpstan" version="^1.10.37" installed="1.10.37" location="./tools/phpstan" copy="false"/>
|
<phar name="phpstan" version="^1.10.37" installed="1.10.46" location="./tools/phpstan" copy="false"/>
|
||||||
<phar name="phan" version="^5.4.2" installed="5.4.2" location="./tools/phan" copy="false"/>
|
<phar name="phan" version="^5.4.2" installed="5.4.2" location="./tools/phan" copy="false"/>
|
||||||
<phar name="psalm" version="^5.15.0" installed="5.15.0" location="./tools/psalm" copy="false"/>
|
<phar name="psalm" version="^5.15.0" installed="5.16.0" location="./tools/psalm" copy="false"/>
|
||||||
<phar name="phpdox" version="^0.12.0" installed="0.12.0" location="./tools/phpdox" copy="false"/>
|
<phar name="phpdox" version="^0.12.0" installed="0.12.0" location="./tools/phpdox" copy="false"/>
|
||||||
<phar name="phpdocumentor" version="^3.4.2" installed="3.4.2" location="./tools/phpDocumentor" copy="false"/>
|
<phar name="phpdocumentor" version="^3.4.2" installed="3.4.3" location="./tools/phpDocumentor" copy="false"/>
|
||||||
<phar name="php-cs-fixer" version="^3.34.1" installed="3.34.1" location="./tools/php-cs-fixer" copy="false"/>
|
<phar name="php-cs-fixer" version="^3.34.1" installed="3.40.0" location="./tools/php-cs-fixer" copy="false"/>
|
||||||
</phive>
|
</phive>
|
||||||
|
|||||||
@@ -1098,16 +1098,109 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
|||||||
* @testdox arrayFlatForKey array $input will be $expected [$_dataName]
|
* @testdox arrayFlatForKey array $input will be $expected [$_dataName]
|
||||||
*
|
*
|
||||||
* @param array $input
|
* @param array $input
|
||||||
|
* @param string $search
|
||||||
* @param array $expected
|
* @param array $expected
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testArrayFlatForKey(array $input, $search, array $expected): void
|
public function testArrayFlatForKey(array $input, string $search, array $expected): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
\CoreLibs\Combined\ArrayHandler::arrayFlatForKey($input, $search)
|
\CoreLibs\Combined\ArrayHandler::arrayFlatForKey($input, $search)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerArrayGetNextPrevKey(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'find, ok' => [
|
||||||
|
'input' => [
|
||||||
|
'a' => 'First',
|
||||||
|
'b' => 'Second',
|
||||||
|
'c' => 'Third',
|
||||||
|
],
|
||||||
|
'b',
|
||||||
|
'a',
|
||||||
|
'c'
|
||||||
|
],
|
||||||
|
'find, first' => [
|
||||||
|
'input' => [
|
||||||
|
'a' => 'First',
|
||||||
|
'b' => 'Second',
|
||||||
|
'c' => 'Third',
|
||||||
|
],
|
||||||
|
'a',
|
||||||
|
null,
|
||||||
|
'b'
|
||||||
|
],
|
||||||
|
'find, last' => [
|
||||||
|
'input' => [
|
||||||
|
'a' => 'First',
|
||||||
|
'b' => 'Second',
|
||||||
|
'c' => 'Third',
|
||||||
|
],
|
||||||
|
'c',
|
||||||
|
'b',
|
||||||
|
null
|
||||||
|
],
|
||||||
|
'find, not found' => [
|
||||||
|
'input' => [
|
||||||
|
'a' => 'First',
|
||||||
|
'b' => 'Second',
|
||||||
|
'c' => 'Third',
|
||||||
|
],
|
||||||
|
'z',
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
],
|
||||||
|
'int, index' => [
|
||||||
|
'input' => [
|
||||||
|
'a',
|
||||||
|
'b',
|
||||||
|
'c'
|
||||||
|
],
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
2
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::arrayGetPrevKey, ::arrayGetNextKey
|
||||||
|
* @dataProvider providerArrayGetNextPrevKey
|
||||||
|
* @testdox arrayGetNextPrevKey get next/prev key for $search wtih $expected_prev/$expected_next [$_dataName]
|
||||||
|
*
|
||||||
|
* @param array $input
|
||||||
|
* @param int|string $search
|
||||||
|
* @param int|string|null $expected_prev
|
||||||
|
* @param int|string|null $expected_next
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testArrayGetNextPrevKey(
|
||||||
|
array $input,
|
||||||
|
int|string $search,
|
||||||
|
int|string|null $expected_prev,
|
||||||
|
int|string|null $expected_next
|
||||||
|
): void {
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_prev,
|
||||||
|
\CoreLibs\Combined\ArrayHandler::arrayGetPrevKey($input, $search),
|
||||||
|
'Find prev key in array'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_next,
|
||||||
|
\CoreLibs\Combined\ArrayHandler::arrayGetNextKey($input, $search),
|
||||||
|
'Find next key in array'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
15
jsconfig.json
Normal file
15
jsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "Node",
|
||||||
|
"target": "ES2020",
|
||||||
|
"jsx": "react",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"strictNullChecks": true,
|
||||||
|
"strictFunctionTypes": true
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"node_modules",
|
||||||
|
"**/node_modules/*"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1 +1 @@
|
|||||||
/home/clemens/.phive/phars/php-cs-fixer-3.34.1.phar
|
/home/clemens/.phive/phars/php-cs-fixer-3.40.0.phar
|
||||||
@@ -1 +1 @@
|
|||||||
/home/clemens/.phive/phars/phpdocumentor-3.4.2.phar
|
/home/clemens/.phive/phars/phpdocumentor-3.4.3.phar
|
||||||
@@ -1 +1 @@
|
|||||||
/home/clemens/.phive/phars/phpstan-1.10.37.phar
|
/home/clemens/.phive/phars/phpstan-1.10.46.phar
|
||||||
@@ -1 +1 @@
|
|||||||
/home/clemens/.phive/phars/psalm-5.15.0.phar
|
/home/clemens/.phive/phars/psalm-5.16.0.phar
|
||||||
@@ -21,6 +21,7 @@ ob_end_flush();
|
|||||||
use CoreLibs\Combined\ArrayHandler;
|
use CoreLibs\Combined\ArrayHandler;
|
||||||
use CoreLibs\Debug\Support as DgS;
|
use CoreLibs\Debug\Support as DgS;
|
||||||
use CoreLibs\Convert\SetVarType;
|
use CoreLibs\Convert\SetVarType;
|
||||||
|
use PHPUnit\Framework\Constraint\ArrayHasKey;
|
||||||
|
|
||||||
$log = new CoreLibs\Logging\Logging([
|
$log = new CoreLibs\Logging\Logging([
|
||||||
'log_folder' => BASE . LOG,
|
'log_folder' => BASE . LOG,
|
||||||
@@ -236,6 +237,22 @@ $flag = false;
|
|||||||
$output = \CoreLibs\Combined\ArrayHandler::genAssocArray($db_array, $key, $value, $flag);
|
$output = \CoreLibs\Combined\ArrayHandler::genAssocArray($db_array, $key, $value, $flag);
|
||||||
print "OUTPUT: " . \CoreLibs\Debug\Support::printAr($output) . "<br>";
|
print "OUTPUT: " . \CoreLibs\Debug\Support::printAr($output) . "<br>";
|
||||||
|
|
||||||
|
|
||||||
|
print "<hr>";
|
||||||
|
$array = [
|
||||||
|
'a' => 'First',
|
||||||
|
'b' => 'Second',
|
||||||
|
'c' => 'Third',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach (array_keys($array) as $search) {
|
||||||
|
print "Result[" . $search . "]: "
|
||||||
|
. "next: " . DgS::printAr(ArrayHandler::arrayGetNextKey($array, $search)) . ", "
|
||||||
|
. "prev: " . DgS::printAr(ArrayHandler::arrayGetPrevKey($array, $search))
|
||||||
|
. "<br>";
|
||||||
|
}
|
||||||
|
print "Key not exists: " . DgS::printAr(ArrayHandler::arrayGetNextKey($array, 'z')) . "<br>";
|
||||||
|
|
||||||
print "</body></html>";
|
print "</body></html>";
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -115,6 +115,8 @@ echo "INSERT ALL COLUMN TYPES: "
|
|||||||
. "ERROR: " . $db->dbGetLastError(true) . "<br>";
|
. "ERROR: " . $db->dbGetLastError(true) . "<br>";
|
||||||
echo "<hr>";
|
echo "<hr>";
|
||||||
|
|
||||||
|
// test connectors: = , <> () for query detection
|
||||||
|
|
||||||
// convert placeholder tests
|
// convert placeholder tests
|
||||||
// ? -> $n
|
// ? -> $n
|
||||||
// :name -> $n
|
// :name -> $n
|
||||||
|
|||||||
@@ -236,6 +236,54 @@ class ArrayHandler
|
|||||||
return $hit_list;
|
return $hit_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* main wrapper function for next/prev key
|
||||||
|
*
|
||||||
|
* @param array<mixed> $array array to search in
|
||||||
|
* @param int|string $key key for next/prev
|
||||||
|
* @param bool $next [=true] if to search next or prev
|
||||||
|
* @return int|string|null Next/prev key or null for end/first
|
||||||
|
*/
|
||||||
|
private static function arrayGetKey(array $array, int|string $key, bool $next = true): int|string|null
|
||||||
|
{
|
||||||
|
$keys = array_keys($array);
|
||||||
|
if (($position = array_search($key, $keys, true)) === false) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$next_position = $next ? $position + 1 : $position - 1;
|
||||||
|
|
||||||
|
if (!isset($keys[$next_position])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return $keys[$next_position];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get previous array key from an array
|
||||||
|
* null on not found
|
||||||
|
*
|
||||||
|
* @param array<mixed> $array
|
||||||
|
* @param int|string $key
|
||||||
|
* @return int|string|null Next key, or null for not found
|
||||||
|
*/
|
||||||
|
public static function arrayGetPrevKey(array $array, int|string $key): int|string|null
|
||||||
|
{
|
||||||
|
return self::arrayGetKey($array, $key, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get next array key from an array
|
||||||
|
* null on not found
|
||||||
|
*
|
||||||
|
* @param array<mixed> $array
|
||||||
|
* @param int|string $key
|
||||||
|
* @return int|string|null Next key, or null for not found
|
||||||
|
*/
|
||||||
|
public static function arrayGetNextKey(array $array, int|string $key): int|string|null
|
||||||
|
{
|
||||||
|
return self::arrayGetKey($array, $key, true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* correctly recursive merges as an array as array_merge_recursive
|
* correctly recursive merges as an array as array_merge_recursive
|
||||||
* just glues things together
|
* just glues things together
|
||||||
|
|||||||
@@ -385,7 +385,7 @@ class DateTime
|
|||||||
} else {
|
} else {
|
||||||
$str = implode(', ', array_slice($formatted, 0, -1));
|
$str = implode(', ', array_slice($formatted, 0, -1));
|
||||||
if (!empty($formatted[count($formatted) - 1])) {
|
if (!empty($formatted[count($formatted) - 1])) {
|
||||||
$str .= ' and ' . $formatted[count($formatted) - 1];
|
$str .= ' and ' . (string)array_pop($formatted);
|
||||||
}
|
}
|
||||||
return $negative . $str;
|
return $negative . $str;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1318,14 +1318,14 @@ class IO
|
|||||||
// regex for params: only stand alone $number allowed
|
// regex for params: only stand alone $number allowed
|
||||||
// exclude all '' enclosed strings, ignore all numbers [note must start with digit]
|
// exclude all '' enclosed strings, ignore all numbers [note must start with digit]
|
||||||
// can have space/tab/new line
|
// can have space/tab/new line
|
||||||
// must have = , ( [equal, comma, opening round bracket]
|
// must have <> = , ( [not equal, equal, comma, opening round bracket]
|
||||||
// can have space/tab/new line
|
// can have space/tab/new line
|
||||||
// $ number with 1-9 for first and 0-9 for further digits
|
// $ number with 1-9 for first and 0-9 for further digits
|
||||||
// /s for matching new line in . list
|
// /s for matching new line in . list
|
||||||
// [disabled, we don't used ^ or $] /m for multi line match
|
// [disabled, we don't used ^ or $] /m for multi line match
|
||||||
// Matches in 1:, must be array_filtered to remove empty, count with array_unique
|
// Matches in 1:, must be array_filtered to remove empty, count with array_unique
|
||||||
preg_match_all(
|
preg_match_all(
|
||||||
'/(?:\'.*?\')?\s*(?:\?\?|[(=,])\s*(?:\d+|(?:\'.*?\')|(\$[1-9]{1}(?:[0-9]{1,})?))/s',
|
'/(?:\'.*?\')?\s*(?:\?\?|<>|[(=,])\s*(?:\d+|(?:\'.*?\')|(\$[1-9]{1}(?:[0-9]{1,})?))/s',
|
||||||
$query,
|
$query,
|
||||||
$match
|
$match
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user