diff --git a/.phive/phars.xml b/.phive/phars.xml
index 72b47dc..c72f3a2 100644
--- a/.phive/phars.xml
+++ b/.phive/phars.xml
@@ -1,9 +1,9 @@
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/src/Check/File.php b/src/Check/File.php
index 36b4bfc..c8bdc53 100644
--- a/src/Check/File.php
+++ b/src/Check/File.php
@@ -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__
diff --git a/src/Combined/DateTime.php b/src/Combined/DateTime.php
index b4c5d65..d46619c 100644
--- a/src/Combined/DateTime.php
+++ b/src/Combined/DateTime.php
@@ -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) {
diff --git a/src/Convert/Strings.php b/src/Convert/Strings.php
index bcbaf05..2935e26 100644
--- a/src/Convert/Strings.php
+++ b/src/Convert/Strings.php
@@ -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__
diff --git a/src/DB/IO.php b/src/DB/IO.php
index 35c81a5..efe3901 100644
--- a/src/DB/IO.php
+++ b/src/DB/IO.php
@@ -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'] ==
diff --git a/src/Output/Form/Generate.php b/src/Output/Form/Generate.php
index 8553187..3c406d4 100644
--- a/src/Output/Form/Generate.php
+++ b/src/Output/Form/Generate.php
@@ -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;
diff --git a/src/Output/Image.php b/src/Output/Image.php
index 4114494..9fd8261 100644
--- a/src/Output/Image.php
+++ b/src/Output/Image.php
@@ -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;
}
}
diff --git a/src/Output/ProgressBar.php b/src/Output/ProgressBar.php
index 6affd99..5c4f9c7 100644
--- a/src/Output/ProgressBar.php
+++ b/src/Output/ProgressBar.php
@@ -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) {
diff --git a/test/phpunit/Check/CoreLibsCheckFileTest.php b/test/phpunit/Check/CoreLibsCheckFileTest.php
index c94ad94..56141aa 100644
--- a/test/phpunit/Check/CoreLibsCheckFileTest.php
+++ b/test/phpunit/Check/CoreLibsCheckFileTest.php
@@ -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__
diff --git a/test/phpunit/Convert/CoreLibsConvertStringsTest.php b/test/phpunit/Convert/CoreLibsConvertStringsTest.php
index 90415d2..0b2f79a 100644
--- a/test/phpunit/Convert/CoreLibsConvertStringsTest.php
+++ b/test/phpunit/Convert/CoreLibsConvertStringsTest.php
@@ -256,6 +256,80 @@ final class CoreLibsConvertStringsTest extends TestCase
$output
);
}
+
+ /**
+ * provider for testStripMultiplePathSlashes
+ *
+ * @return array
+ */
+ 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__
diff --git a/tools/phan b/tools/phan
index 7b7c46b..66d455f 120000
--- a/tools/phan
+++ b/tools/phan
@@ -1 +1 @@
-/home/clemens/.phive/phars/phan-5.4.2.phar
\ No newline at end of file
+/home/clemens/.phive/phars/phan-5.4.3.phar
\ No newline at end of file
diff --git a/tools/phpcbf b/tools/phpcbf
index 559cdd1..9c2ef34 120000
--- a/tools/phpcbf
+++ b/tools/phpcbf
@@ -1 +1 @@
-/home/clemens/.phive/phars/phpcbf-3.7.2.phar
\ No newline at end of file
+/home/clemens/.phive/phars/phpcbf-3.9.0.phar
\ No newline at end of file
diff --git a/tools/phpcs b/tools/phpcs
index d05d09d..5b36847 120000
--- a/tools/phpcs
+++ b/tools/phpcs
@@ -1 +1 @@
-/home/clemens/.phive/phars/phpcs-3.7.2.phar
\ No newline at end of file
+/home/clemens/.phive/phars/phpcs-3.9.0.phar
\ No newline at end of file
diff --git a/tools/phpstan b/tools/phpstan
index 0d01a2f..997e355 120000
--- a/tools/phpstan
+++ b/tools/phpstan
@@ -1 +1 @@
-/home/clemens/.phive/phars/phpstan-1.10.46.phar
\ No newline at end of file
+/home/clemens/.phive/phars/phpstan-1.10.59.phar
\ No newline at end of file
diff --git a/tools/phpunit b/tools/phpunit
index f802b8f..c40fcfc 120000
--- a/tools/phpunit
+++ b/tools/phpunit
@@ -1 +1 @@
-/home/clemens/.phive/phars/phpunit-9.6.13.phar
\ No newline at end of file
+/home/clemens/.phive/phars/phpunit-9.6.17.phar
\ No newline at end of file
diff --git a/tools/psalm b/tools/psalm
index 38c37c8..ae422a1 120000
--- a/tools/psalm
+++ b/tools/psalm
@@ -1 +1 @@
-/home/clemens/.phive/phars/psalm-5.16.0.phar
\ No newline at end of file
+/home/clemens/.phive/phars/psalm-5.22.2.phar
\ No newline at end of file