Use more explicit type hints for improved static code analysis

This commit is contained in:
2024-09-22 16:51:54 +02:00
parent bce4268a70
commit fa2985463f
2 changed files with 32 additions and 22 deletions

View File

@ -21,7 +21,7 @@ final class MD_STD_Test extends TestCase {
/**
* Data provider for returning a tmp file.
*
* @return array<string, array{0: string, 1: string}>
* @return array<string, array{0: non-empty-string}>
*/
public static function file_name_in_tmp_provider():array {
@ -37,7 +37,7 @@ final class MD_STD_Test extends TestCase {
/**
* Data provider for invalid directories.
*
* @return array<string, array{0: string}>
* @return array<non-empty-string, array{0: non-empty-string}>
*/
public static function invalid_directory_provider():array {
@ -118,7 +118,7 @@ final class MD_STD_Test extends TestCase {
/**
* Checks if a file can be written.
*
* @param string $temp_file Tmp file.
* @param non-empty-string $temp_file Tmp file.
*
* @return void
*/
@ -146,8 +146,8 @@ final class MD_STD_Test extends TestCase {
/**
* Check MD_STD::realpath throws exception on non-existing path.
*
* @param string $to_validate Input to validate.
* @param string $exceptionClass Exception class.
* @param non-empty-string $to_validate Input to validate.
* @param class-string<Throwable> $exceptionClass Exception class.
*
* @return void
*/
@ -162,8 +162,8 @@ final class MD_STD_Test extends TestCase {
/**
* Checks if a file can be read.
*
* @param string $to_validate Input to validate.
* @param string $exceptionClass Exception class.
* @param non-empty-string $to_validate Input to validate.
* @param class-string<Throwable> $exceptionClass Exception class.
*
* @return void
*/
@ -229,7 +229,7 @@ final class MD_STD_Test extends TestCase {
/**
* Checks if nothing happens if a file does not exist.
*
* @param string $temp_file Tmp file.
* @param non-empty-string $temp_file Tmp file.
*
* @return void
*/
@ -248,7 +248,7 @@ final class MD_STD_Test extends TestCase {
/**
* Checks unlink_if_exists works.
*
* @param string $temp_file Tmp file.
* @param non-empty-string $temp_file Tmp file.
*
* @return void
*/
@ -268,7 +268,10 @@ final class MD_STD_Test extends TestCase {
*/
public function test_scandir():void {
$files = scandir(__DIR__);
if (empty($files = scandir(__DIR__))) {
throw new Exception("Running regular scandir() failed on script directory: " . __DIR__);
}
$filesChecked = MD_STD::scandir(__DIR__);
foreach ($filesChecked as $file) {
@ -284,7 +287,7 @@ final class MD_STD_Test extends TestCase {
/**
* Checks invalid directory.
*
* @param string $dir Dir name.
* @param non-empty-string $dir Dir name.
*
* @return void
*/
@ -520,9 +523,9 @@ final class MD_STD_Test extends TestCase {
/**
* Checks that minimizeHTMLString works.
*
* @param string $filepath File path.
* @param array<string> $mime_types Mime types expected.
* @param string $exception Exception class name.
* @param non-empty-string $filepath File path.
* @param array<string> $mime_types Mime types expected.
* @param class-string<Throwable> $exception Exception class.
*
* @return void
*/
@ -568,7 +571,7 @@ final class MD_STD_Test extends TestCase {
/**
* Checks check_is_writable does not work with non-existent or non-directory paths.
*
* @param string $dir Dir name.
* @param non-empty-string $dir Dir name.
*
* @return void
*/