diff options
| author | 2023-05-22 20:55:59 +0200 | |
|---|---|---|
| committer | 2023-05-22 20:55:59 +0200 | |
| commit | 445cc23abdda5767b622d70cf7b5eb5310dcf908 (patch) | |
| tree | d3f4d05416576da2a0cd7e45eb768f1c2f900f08 /lib/Minz | |
| parent | d554d0f6736c5cf94cb2a8fa61f3b6187b86ffa2 (diff) | |
PHPStan Level 7 complete (#5406)
* PHPStan Level 7 complete
* Start PHPStan Level 8
* Forgot exclude .phtml
Diffstat (limited to 'lib/Minz')
| -rw-r--r-- | lib/Minz/Configuration.php | 2 | ||||
| -rw-r--r-- | lib/Minz/Mailer.php | 4 | ||||
| -rw-r--r-- | lib/Minz/Migrator.php | 20 | ||||
| -rw-r--r-- | lib/Minz/Pdo.php | 2 |
4 files changed, 13 insertions, 15 deletions
diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php index 4ed0233f4..bbe20b153 100644 --- a/lib/Minz/Configuration.php +++ b/lib/Minz/Configuration.php @@ -9,7 +9,7 @@ * @property-read string $environment * @property array<string,bool> $extensions_enabled * @property-read string $mailer - * @property-read array<string|int|bool> $smtp + * @property-read array{'hostname':string,'host':string,'auth':bool,'username':string,'password':string,'secure':string,'port':int,'from':string} $smtp * @property string $title */ class Minz_Configuration { diff --git a/lib/Minz/Mailer.php b/lib/Minz/Mailer.php index cf6c64bad..7cf99a667 100644 --- a/lib/Minz/Mailer.php +++ b/lib/Minz/Mailer.php @@ -34,7 +34,7 @@ class Minz_Mailer { /** @var string */ private $mailer; - /** @var array<string|int|bool> */ + /** @var array{'hostname':string,'host':string,'auth':bool,'username':string,'password':string,'secure':string,'port':int,'from':string} */ private $smtp_config; /** @var int */ private $debug_level; @@ -71,7 +71,7 @@ class Minz_Mailer { public function mail(string $to, string $subject): bool { ob_start(); $this->view->render(); - $body = ob_get_contents(); + $body = ob_get_contents() ?: ''; ob_end_clean(); PHPMailer::$validator = 'html5'; 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; } diff --git a/lib/Minz/Pdo.php b/lib/Minz/Pdo.php index 14acd484d..05015040a 100644 --- a/lib/Minz/Pdo.php +++ b/lib/Minz/Pdo.php @@ -50,7 +50,7 @@ abstract class Minz_Pdo extends PDO { // PHP8+: PDO::prepare(string $query, array $options = []): PDOStatement|false /** * @param string $query - * @param array<int,string>|null $options + * @param array<int,string> $options * @return PDOStatement|false * @phpstan-ignore-next-line */ |
