aboutsummaryrefslogtreecommitdiff
path: root/lib/Minz/Migrator.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2023-05-22 20:55:59 +0200
committerGravatar GitHub <noreply@github.com> 2023-05-22 20:55:59 +0200
commit445cc23abdda5767b622d70cf7b5eb5310dcf908 (patch)
treed3f4d05416576da2a0cd7e45eb768f1c2f900f08 /lib/Minz/Migrator.php
parentd554d0f6736c5cf94cb2a8fa61f3b6187b86ffa2 (diff)
PHPStan Level 7 complete (#5406)
* PHPStan Level 7 complete * Start PHPStan Level 8 * Forgot exclude .phtml
Diffstat (limited to 'lib/Minz/Migrator.php')
-rw-r--r--lib/Minz/Migrator.php20
1 files changed, 9 insertions, 11 deletions
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<string> */
+ /** @var array<callable> */
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;
}