diff --git a/src/Arr.php b/src/Arr.php index 8a3abea..cde3f29 100644 --- a/src/Arr.php +++ b/src/Arr.php @@ -38,7 +38,7 @@ public static function unique(array $array, bool $keepKeys = false): array $uniqueArray[$value] = $key; } - + return \array_flip($uniqueArray); } diff --git a/src/FS.php b/src/FS.php index 2313dff..a7f8a8d 100644 --- a/src/FS.php +++ b/src/FS.php @@ -173,9 +173,14 @@ public static function openFile(string $filepath): ?string $realPath = \realpath($filepath); if ($realPath !== false) { - $handle = \fopen($realPath, 'r'); + $handle = \fopen($realPath, 'r'); + $fileSize = (int)\filesize($realPath); + if ($fileSize === 0) { + return null; + } + if ($handle !== false) { - $contents = (string)\fread($handle, (int)\filesize($realPath)); + $contents = (string)\fread($handle, $fileSize); \fclose($handle); } } @@ -370,9 +375,9 @@ public static function clean(?string $path, string $dirSep = \DIRECTORY_SEPARATO $path = \trim((string)$path); if (($dirSep === '\\') && ($path[0] === '\\') && ($path[1] === '\\')) { - $path = '\\' . \preg_replace('#[/\\\\]+#', $dirSep, $path); + $path = '\\' . \preg_replace('#[/\\\]+#', $dirSep, $path); } else { - $path = (string)\preg_replace('#[/\\\\]+#', $dirSep, $path); + $path = (string)\preg_replace('#[/\\\]+#', $dirSep, $path); } return $path; diff --git a/tests/FileSystemTest.php b/tests/FileSystemTest.php index 80d7809..634507d 100644 --- a/tests/FileSystemTest.php +++ b/tests/FileSystemTest.php @@ -394,9 +394,9 @@ public function testClean(): void isSame('/path/path', FS::clean('///path///path')); isSame('/path/path/path', FS::clean('///path///path/path')); isSame('/path/path/path/', FS::clean('\path\path\path\\\\\\\\')); - isSame('\\path\\path\\path\\', FS::clean('\path\path\path\\\\\\\\', '\\')); - isSame('\\path\\path\\path\\', FS::clean('\\path\\path\\path\\\\\\\\', '\\')); - isSame('\\\\path\\path\\path\\', FS::clean('\\\\path\\path\\path\\\\\\\\', '\\')); + isSame('\path\path\path\\', FS::clean('\path\path\path\\\\\\\\', '\\')); + isSame('\path\path\path\\', FS::clean('\path\path\path\\\\\\\\', '\\')); + isSame('\\\path\path\path\\', FS::clean('\\\path\path\path\\\\\\\\', '\\')); isSame('../../path/', FS::clean('..///..///path/', '/')); isSame('./../path/', FS::clean('.///..///path/', '/')); @@ -438,10 +438,10 @@ public function testGetRelative(): void $root = __DIR__ . '/..'; isSame('tests/FileSystemTest.php', FS::getRelative($file, $root, '/')); - isSame('tests\\FileSystemTest.php', FS::getRelative($file, $root, '\\')); + isSame('tests\FileSystemTest.php', FS::getRelative($file, $root, '\\')); $root = null; isSame('tests/FileSystemTest.php', FS::getRelative($file, $root, '/')); - isSame('tests\\FileSystemTest.php', FS::getRelative($file, $root, '\\')); + isSame('tests\FileSystemTest.php', FS::getRelative($file, $root, '\\')); } } diff --git a/tests/StringTest.php b/tests/StringTest.php index abbe8bb..69f2657 100644 --- a/tests/StringTest.php +++ b/tests/StringTest.php @@ -74,7 +74,7 @@ public function testClean(): void $input = ' ASDF !@#$%^&*()_+"\';:>< '; isSame('ASDF !@#$%^&*()_+"\';:><', Str::clean($input)); - isSame('asdf !@#$%^&*()_+\\"\\\';:><', Str::clean($input, true, true)); + isSame('asdf !@#$%^&*()_+\"\\\';:><', Str::clean($input, true, true)); } public function testParseLines(): void @@ -272,7 +272,7 @@ public function testEsc(): void { isSame( '<a href="/test">Test !@#$%^&*()_+\/</a>', - Str::esc('Test !@#$%^&*()_+\\/'), + Str::esc('Test !@#$%^&*()_+\/'), ); } @@ -280,7 +280,7 @@ public function testEscXML(): void { isSame( '<a href="/test">Test!@#$%^&*()_+\/</a>', - Str::escXml('Test!@#$%^&*()_+\\/'), + Str::escXml('Test!@#$%^&*()_+\/'), ); } @@ -333,10 +333,10 @@ public function testTestName2Human(): void isSame('Function IE Test', Str::testName2Human('Test_FunctionIE_TestTest')); isSame('Test Function IE Test', Str::testName2Human('Test_testFunctionIE_TestTest')); - isSame('Function IE', Str::testName2Human('\\JBZoo\\Test_FunctionIE_Test')); - isSame('Function IE', Str::testName2Human('\\JBZoo\\PHPHunit\\Test_FunctionIE_Test')); - isSame('Function IE', Str::testName2Human('\\JBZoo\\PHPHunit\\Some\\Test_FunctionIE_Test')); - isSame('Function IE', Str::testName2Human('\\JBZoo\\PHPHunit\\Some\\Some\\Test_FunctionIE_Test')); + isSame('Function IE', Str::testName2Human('\JBZoo\Test_FunctionIE_Test')); + isSame('Function IE', Str::testName2Human('\JBZoo\PHPHunit\Test_FunctionIE_Test')); + isSame('Function IE', Str::testName2Human('\JBZoo\PHPHunit\Some\Test_FunctionIE_Test')); + isSame('Function IE', Str::testName2Human('\JBZoo\PHPHunit\Some\Some\Test_FunctionIE_Test')); } public function testGenerateUUID(): void diff --git a/tests/SysTest.php b/tests/SysTest.php index dbabf17..fe3a2cc 100644 --- a/tests/SysTest.php +++ b/tests/SysTest.php @@ -89,7 +89,7 @@ public function testGetDocumentRoot(): void $_SERVER['DOCUMENT_ROOT'] = '../../'; isSame(\realpath('../../'), Sys::getDocRoot()); - $_SERVER['DOCUMENT_ROOT'] = __DIR__ . '\\..\\'; + $_SERVER['DOCUMENT_ROOT'] = __DIR__ . '\..\\'; isSame(PROJECT_ROOT, Sys::getDocRoot()); } diff --git a/tests/XmlTest.php b/tests/XmlTest.php index 7ad8832..0dedf15 100644 --- a/tests/XmlTest.php +++ b/tests/XmlTest.php @@ -263,7 +263,7 @@ public function testEscape(): void { isSame( '<a href="/test">Test!@#$%^&*()_+\/</a>', - Xml::escape('Test!@#$%^&*()_+\\/'), + Xml::escape('Test!@#$%^&*()_+\/'), ); }