diff options
| author | 2023-05-22 20:55:59 +0200 | |
|---|---|---|
| committer | 2023-05-22 20:55:59 +0200 | |
| commit | 445cc23abdda5767b622d70cf7b5eb5310dcf908 (patch) | |
| tree | d3f4d05416576da2a0cd7e45eb768f1c2f900f08 /lib | |
| parent | d554d0f6736c5cf94cb2a8fa61f3b6187b86ffa2 (diff) | |
PHPStan Level 7 complete (#5406)
* PHPStan Level 7 complete
* Start PHPStan Level 8
* Forgot exclude .phtml
Diffstat (limited to 'lib')
| -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 | ||||
| -rw-r--r-- | lib/core-extensions/Google-Groups/extension.php | 2 | ||||
| -rw-r--r-- | lib/lib_date.php | 4 |
6 files changed, 17 insertions, 17 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 */ diff --git a/lib/core-extensions/Google-Groups/extension.php b/lib/core-extensions/Google-Groups/extension.php index cdd605cd9..eb30de5f9 100644 --- a/lib/core-extensions/Google-Groups/extension.php +++ b/lib/core-extensions/Google-Groups/extension.php @@ -6,6 +6,6 @@ class GoogleGroupsExtension extends Minz_Extension { } public static function findFeed(string $url): string { - return preg_replace('%^(https?://groups.google.com/forum)/#!forum/(.+)$%i', '$1/feed/$2/msgs/rss.xml', $url); + return preg_replace('%^(https?://groups.google.com/forum)/#!forum/(.+)$%i', '$1/feed/$2/msgs/rss.xml', $url) ?? ''; } } diff --git a/lib/lib_date.php b/lib/lib_date.php index c1b40ecf6..70c1517af 100644 --- a/lib/lib_date.php +++ b/lib/lib_date.php @@ -63,6 +63,7 @@ function _dateCeiling(string $isoDate): string { return $x[0] . 'T' . $t; } +/** @phpstan-return ($isoDate is null ? null : ($isoDate is '' ? null : string)) */ function _noDelimit(?string $isoDate): ?string { return $isoDate === null || $isoDate === '' ? null : str_replace(array('-', ':'), '', $isoDate); //FIXME: Bug with negative time zone } @@ -70,7 +71,8 @@ function _noDelimit(?string $isoDate): ?string { function _dateRelative(?string $d1, ?string $d2): ?string { if ($d2 === null) { return $d1 !== null && $d1[0] !== 'P' ? $d1 : null; - } elseif ($d2 !== '' && $d2[0] != 'P' && $d1 !== null && $d1[0] !== 'P') { + } + if ($d2 !== '' && $d2[0] != 'P' && $d1 !== null && $d1[0] !== 'P') { $y2 = substr($d2, 0, 4); if (strlen($y2) < 4 || !ctype_digit($y2)) { //Does not start by a year $d2 = _noDelimit($d2); |
