From 445cc23abdda5767b622d70cf7b5eb5310dcf908 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 22 May 2023 20:55:59 +0200 Subject: PHPStan Level 7 complete (#5406) * PHPStan Level 7 complete * Start PHPStan Level 8 * Forgot exclude .phtml --- lib/Minz/Migrator.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'lib/Minz/Migrator.php') diff --git a/lib/Minz/Migrator.php b/lib/Minz/Migrator.php index d6dbf94d1..e723934f1 100644 --- a/lib/Minz/Migrator.php +++ b/lib/Minz/Migrator.php @@ -12,7 +12,7 @@ class Minz_Migrator /** @var string[] */ private $applied_versions; - /** @var array */ + /** @var array */ private $migrations = []; /** @@ -37,7 +37,7 @@ class Minz_Migrator } $applied_migrations = array_filter(explode("\n", $applied_migrations)); - $migration_files = scandir($migrations_path); + $migration_files = scandir($migrations_path) ?: []; $migration_files = array_filter($migration_files, static function (string $filename) { $file_extension = pathinfo($filename, PATHINFO_EXTENSION); return $file_extension === 'php'; @@ -131,7 +131,7 @@ class Minz_Migrator return; } - foreach (scandir($directory) as $filename) { + foreach (scandir($directory) ?: [] as $filename) { $file_extension = pathinfo($filename, PATHINFO_EXTENSION); if ($file_extension !== 'php') { continue; @@ -149,6 +149,10 @@ class Minz_Migrator ADMIN_LOG ); } + + if (!is_callable($migration_callback)) { + throw new BadFunctionCallException("{$migration_version} migration cannot be called."); + } $this->addMigration($migration_version, $migration_callback); } } @@ -158,17 +162,11 @@ class Minz_Migrator * * @param string $version The version of the migration (be careful, migrations * are sorted with the `strnatcmp` function) - * @param ?callable $callback The migration function to execute, it should + * @param callable $callback The migration function to execute, it should * return true on success and must return false * on error - * - * @throws BadFunctionCallException if the callback isn’t callable. */ - public function addMigration(string $version, ?callable $callback): void { - if (!is_callable($callback)) { - throw new BadFunctionCallException("{$version} migration cannot be called."); - } - + public function addMigration(string $version, callable $callback): void { $this->migrations[$version] = $callback; } -- cgit v1.2.3