tools update, bug fix Strings to return path if null, Fix form list loader, fix paths
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phive xmlns="https://phar.io/phive">
|
||||
<phar name="phpunit" version="^9.6" installed="9.6.13" location="./tools/phpunit" copy="false"/>
|
||||
<phar name="phpcs" version="^3.7.2" installed="3.7.2" location="./tools/phpcs" copy="false"/>
|
||||
<phar name="phpcbf" version="^3.7.2" installed="3.7.2" location="./tools/phpcbf" copy="false"/>
|
||||
<phar name="psalm" version="^5.15.0" installed="5.16.0" location="./tools/psalm" 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="phpunit" version="^9.6" installed="9.6.17" location="./tools/phpunit" copy="false"/>
|
||||
<phar name="phpcs" version="^3.7.2" installed="3.9.0" location="./tools/phpcs" copy="false"/>
|
||||
<phar name="phpcbf" version="^3.7.2" installed="3.9.0" location="./tools/phpcbf" copy="false"/>
|
||||
<phar name="psalm" version="^5.15.0" installed="5.22.2" location="./tools/psalm" copy="false"/>
|
||||
<phar name="phpstan" version="^1.10.37" installed="1.10.59" location="./tools/phpstan" copy="false"/>
|
||||
<phar name="phan" version="^5.4.2" installed="5.4.3" location="./tools/phan" copy="false"/>
|
||||
</phive>
|
||||
|
||||
@@ -51,6 +51,23 @@ class File
|
||||
// return lines in file
|
||||
return $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the mime type of a file via finfo
|
||||
* if file not found, throws exception
|
||||
* else returns '' for any other finfo read problem
|
||||
*
|
||||
* @param string $read_file File to read, relative or absolute path
|
||||
* @return string
|
||||
*/
|
||||
public static function getMimeType(string $read_file): string
|
||||
{
|
||||
$finfo = new \finfo(FILEINFO_MIME_TYPE);
|
||||
if (!is_file($read_file)) {
|
||||
throw new \UnexpectedValueException('[getMimeType] File not found: ' . $read_file);
|
||||
}
|
||||
return $finfo->file($read_file) ?: '';
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -675,9 +675,9 @@ class DateTime
|
||||
foreach ($period as $dt) {
|
||||
$curr = $dt->format('D');
|
||||
if ($curr == 'Sat' || $curr == 'Sun') {
|
||||
$days[2] ++;
|
||||
$days[2]++;
|
||||
} else {
|
||||
$days[1] ++;
|
||||
$days[1]++;
|
||||
}
|
||||
}
|
||||
if ($return_named === true) {
|
||||
|
||||
@@ -118,6 +118,22 @@ class Strings
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip any duplicated slahes from a path
|
||||
* eg: //foo///bar/foo.inc -> /foo/bar/foo.inc
|
||||
*
|
||||
* @param string $path Path to strip slashes from
|
||||
* @return string Clean path, on error returns original path
|
||||
*/
|
||||
public static function stripMultiplePathSlashes(string $path): string
|
||||
{
|
||||
return preg_replace(
|
||||
'#/+#',
|
||||
'/',
|
||||
$path
|
||||
) ?? $path;
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -1302,7 +1302,7 @@ class IO
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->cursor_ext[$query_hash]['pos'] ++;
|
||||
$this->cursor_ext[$query_hash]['pos']++;
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -1519,7 +1519,7 @@ class IO
|
||||
]);
|
||||
return false;
|
||||
}
|
||||
$this->query_called[$query_hash] ++;
|
||||
$this->query_called[$query_hash]++;
|
||||
// return hash
|
||||
return $query_hash;
|
||||
}
|
||||
@@ -2469,7 +2469,7 @@ class IO
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$this->cursor_ext[$query_hash]['log_pos'] ++;
|
||||
$this->cursor_ext[$query_hash]['log_pos']++;
|
||||
}
|
||||
// reset log for each read
|
||||
$this->cursor_ext[$query_hash]['log'] = [];
|
||||
@@ -2668,8 +2668,8 @@ class IO
|
||||
if ($return) {
|
||||
$this->cursor_ext[$query_hash]['log'][] = 'Return Data';
|
||||
// internal position counter
|
||||
$this->cursor_ext[$query_hash]['pos'] ++;
|
||||
$this->cursor_ext[$query_hash]['read_rows'] ++;
|
||||
$this->cursor_ext[$query_hash]['pos']++;
|
||||
$this->cursor_ext[$query_hash]['read_rows']++;
|
||||
// read is finished
|
||||
if (
|
||||
$this->cursor_ext[$query_hash]['read_rows'] ==
|
||||
|
||||
@@ -826,27 +826,28 @@ class Generate
|
||||
$pk_selected = $res[$this->int_pk_name];
|
||||
}
|
||||
$t_string = '';
|
||||
foreach ($this->field_array as $i => $field_array) {
|
||||
foreach ($this->field_array as $field_array) {
|
||||
if ($t_string) {
|
||||
$t_string .= ', ';
|
||||
}
|
||||
if (isset($field_array['before_value'])) {
|
||||
$t_string .= $field_array['before_value'];
|
||||
if (!empty($field_array['before_value'])) {
|
||||
$t_string .= $this->l->__($field_array['before_value']);
|
||||
}
|
||||
// must have res element set
|
||||
if (
|
||||
isset($field_array['name']) &&
|
||||
!empty($field_array['name']) &&
|
||||
isset($res[$field_array['name']])
|
||||
) {
|
||||
if (isset($field_array['binary'])) {
|
||||
if (isset($field_array['binary'][0])) {
|
||||
$t_string .= $field_array['binary'][0];
|
||||
} elseif (isset($field_array['binary'][1])) {
|
||||
$t_string .= $field_array['binary'][1];
|
||||
}
|
||||
$_t_value = '';
|
||||
// if we have a binary set, where 0 = YES and 1 = NO
|
||||
if (!empty($field_array['binary'])) {
|
||||
$_t_value = !empty($res[$field_array['name']]) ?
|
||||
($field_array['binary'][0] ?? 'Yes') :
|
||||
($field_array['binary'][1] ?? 'No');
|
||||
} else {
|
||||
$t_string .= $res[$field_array['name']];
|
||||
$_t_value = $res[$field_array['name']];
|
||||
}
|
||||
$t_string .= $this->l->__($_t_value);
|
||||
}
|
||||
}
|
||||
$pk_names[] = $t_string;
|
||||
|
||||
@@ -204,11 +204,11 @@ class Image
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// NOTE: we need to depracte this
|
||||
$cache_folder = BASE . LAYOUT . CONTENT_PATH . CACHE . IMAGES;
|
||||
$cache_folder = BASE . CONTENT_PATH . LAYOUT . CACHE . IMAGES;
|
||||
$web_folder = LAYOUT . CACHE . IMAGES;
|
||||
if (!is_dir($cache_folder)) {
|
||||
if (false === mkdir($cache_folder)) {
|
||||
$cache_folder = BASE . LAYOUT . CONTENT_PATH . CACHE;
|
||||
$cache_folder = BASE . CONTENT_PATH . LAYOUT . CACHE;
|
||||
$web_folder = LAYOUT . CACHE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ class ProgressBar
|
||||
{
|
||||
// avoid divison through 0
|
||||
if ($this->max - $this->min == 0) {
|
||||
$this->max ++;
|
||||
$this->max++;
|
||||
}
|
||||
$percent = round(($step - $this->min) / ($this->max - $this->min) * 100);
|
||||
if ($percent > 100) {
|
||||
@@ -186,7 +186,7 @@ class ProgressBar
|
||||
}
|
||||
// avoid divison through 0
|
||||
if ($this->max - $this->min == 0) {
|
||||
$this->max ++;
|
||||
$this->max++;
|
||||
}
|
||||
$pixel = round(($step - $this->min) * ($bar - ($this->pedding * 2)) / ($this->max - $this->min));
|
||||
if ($step <= $this->min) {
|
||||
|
||||
@@ -28,10 +28,10 @@ final class CoreLibsCheckFileTest extends TestCase
|
||||
public function filesList(): array
|
||||
{
|
||||
return [
|
||||
['filename.txt', 'txt', 5],
|
||||
['filename.csv', 'csv', 15],
|
||||
['filename.tsv', 'tsv', 0],
|
||||
['file_does_not_exits', '', -1],
|
||||
['filename.txt', 'txt', 5, 'text/plain'],
|
||||
['filename.csv', 'csv', 15, 'text/csv'],
|
||||
['filename.tsv', 'tsv', 0, 'text/plain'],
|
||||
['file_does_not_exits', '', -1, ''],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -63,6 +63,15 @@ final class CoreLibsCheckFileTest extends TestCase
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function mimeTypeProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->filesList() as $row) {
|
||||
$list[$row[0] . ' must be mime type ' . $row[3]] = [$row[0], $row[3]];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if file extension matches
|
||||
*
|
||||
@@ -115,6 +124,51 @@ final class CoreLibsCheckFileTest extends TestCase
|
||||
unlink($this->base_folder . $input);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::getMimeType
|
||||
* @dataProvider mimeTypeProvider
|
||||
* @testdox getMimeType $input must be mime type $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetMimeType(string $input, string $expected): void
|
||||
{
|
||||
if (!empty($expected)) {
|
||||
$file = $this->base_folder . $input;
|
||||
$fp = fopen($file, 'w');
|
||||
switch ($expected) {
|
||||
case 'text/csv':
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
fwrite($fp, '"This is row","' . $expected . '",' . $i . PHP_EOL);
|
||||
}
|
||||
break;
|
||||
case 'text/tsv':
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
fwrite($fp, "\"This is row\"\t\"" . $expected . "\"\t\"" . $i . PHP_EOL);
|
||||
}
|
||||
break;
|
||||
case 'text/plain':
|
||||
fwrite($fp, 'This is mime type: ' . $expected . PHP_EOL);
|
||||
break;
|
||||
}
|
||||
fclose($fp);
|
||||
} else {
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\File::getMimeType($this->base_folder . $input)
|
||||
);
|
||||
// unlink file
|
||||
if (is_file($this->base_folder . $input)) {
|
||||
unlink($this->base_folder . $input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -256,6 +256,80 @@ final class CoreLibsConvertStringsTest extends TestCase
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* provider for testStripMultiplePathSlashes
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function stripMultiplePathSlashesProvider(): array
|
||||
{
|
||||
return [
|
||||
'no slahses' => [
|
||||
'input' => 'string_abc',
|
||||
'expected' => 'string_abc',
|
||||
],
|
||||
'one slash' => [
|
||||
'input' => 'some/foo',
|
||||
'expected' => 'some/foo',
|
||||
],
|
||||
'two slashes' => [
|
||||
'input' => 'some//foo',
|
||||
'expected' => 'some/foo',
|
||||
],
|
||||
'three slashes' => [
|
||||
'input' => 'some///foo',
|
||||
'expected' => 'some/foo',
|
||||
],
|
||||
'slashes in front' => [
|
||||
'input' => '/foo',
|
||||
'expected' => '/foo',
|
||||
],
|
||||
'two slashes in front' => [
|
||||
'input' => '//foo',
|
||||
'expected' => '/foo',
|
||||
],
|
||||
'thee slashes in front' => [
|
||||
'input' => '///foo',
|
||||
'expected' => '/foo',
|
||||
],
|
||||
'slashes in back' => [
|
||||
'input' => 'foo/',
|
||||
'expected' => 'foo/',
|
||||
],
|
||||
'two slashes in back' => [
|
||||
'input' => 'foo//',
|
||||
'expected' => 'foo/',
|
||||
],
|
||||
'thee slashes in back' => [
|
||||
'input' => 'foo///',
|
||||
'expected' => 'foo/',
|
||||
],
|
||||
'multiple slashes' => [
|
||||
'input' => '/foo//bar///string/end_times',
|
||||
'expected' => '/foo/bar/string/end_times',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* test multiple slashes clean up
|
||||
*
|
||||
* @covers ::stripMultiplePathSlashes
|
||||
* @dataProvider stripMultiplePathSlashesProvider
|
||||
* @testdox stripMultiplePathSlashes $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testStripMultiplePathSlashes(string $input, string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Strings::stripMultiplePathSlashes($input)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -1 +1 @@
|
||||
/home/clemens/.phive/phars/phan-5.4.2.phar
|
||||
/home/clemens/.phive/phars/phan-5.4.3.phar
|
||||
@@ -1 +1 @@
|
||||
/home/clemens/.phive/phars/phpcbf-3.7.2.phar
|
||||
/home/clemens/.phive/phars/phpcbf-3.9.0.phar
|
||||
@@ -1 +1 @@
|
||||
/home/clemens/.phive/phars/phpcs-3.7.2.phar
|
||||
/home/clemens/.phive/phars/phpcs-3.9.0.phar
|
||||
@@ -1 +1 @@
|
||||
/home/clemens/.phive/phars/phpstan-1.10.46.phar
|
||||
/home/clemens/.phive/phars/phpstan-1.10.59.phar
|
||||
@@ -1 +1 @@
|
||||
/home/clemens/.phive/phars/phpunit-9.6.13.phar
|
||||
/home/clemens/.phive/phars/phpunit-9.6.17.phar
|
||||
@@ -1 +1 @@
|
||||
/home/clemens/.phive/phars/psalm-5.16.0.phar
|
||||
/home/clemens/.phive/phars/psalm-5.22.2.phar
|
||||
Reference in New Issue
Block a user