Browse Source

Fix up TypeError cases found by PHPStan level 8 (#16951)

* Fix up TypeError cases found by PHPStan level 8

* Fix up TypeError cases found by PHPStan level 8

* Fix erorrs found by phpstan level 8

Co-authored-by: ADmad <admad.coder@gmail.com>
Mark Scherer 3 years ago
parent
commit
c18f1edee3

+ 1 - 0
src/Console/BaseCommand.php

@@ -184,6 +184,7 @@ abstract class BaseCommand implements CommandInterface
             $io->setInteractive(false);
         }
 
+        /** @var int|null */
         return $this->execute($args, $io);
     }
 

+ 4 - 1
src/Console/ConsoleOutput.php

@@ -225,9 +225,12 @@ class ConsoleOutput
             return (string)preg_replace('#</?(?:' . $tags . ')>#', '', $text);
         }
 
+        /** @var callable $callback */
+        $callback = $this->_replaceTags(...);
+
         return (string)preg_replace_callback(
             '/<(?P<tag>[a-z0-9-_]+)>(?P<text>.*?)<\/(\1)>/ims',
-            $this->_replaceTags(...),
+            $callback,
             $text
         );
     }

+ 2 - 2
src/Database/Driver/Postgres.php

@@ -102,11 +102,11 @@ class Postgres extends Driver
         }
 
         if (!empty($config['timezone'])) {
-            $config['init'][] = sprintf('SET timezone = %s', $this->pdo->quote($config['timezone']));
+            $config['init'][] = sprintf('SET timezone = %s', $this->getPdo()->quote($config['timezone']));
         }
 
         foreach ($config['init'] as $command) {
-            $this->pdo->exec($command);
+            $this->getPdo()->exec($command);
         }
     }
 

+ 2 - 2
src/Database/Type/DateType.php

@@ -57,9 +57,9 @@ class DateType extends BaseType implements BatchCastingInterface
      *
      * See `Cake\I18n\Time::parseDateTime()` for accepted formats.
      *
-     * @var string|int|null
+     * @var array|string|int|null
      */
-    protected string|int|null $_localeMarshalFormat = null;
+    protected array|string|int|null $_localeMarshalFormat = null;
 
     /**
      * The classname to use when creating objects.

+ 0 - 1
src/Database/Type/TimeType.php

@@ -116,7 +116,6 @@ class TimeType extends DateTimeType
         /** @psalm-var class-string<\Cake\I18n\DateTime> $class */
         $class = $this->_className;
 
-        /** @psalm-suppress PossiblyInvalidArgument */
         return $class::parseTime($value, $this->_localeMarshalFormat);
     }
 

+ 1 - 0
src/Event/EventManager.php

@@ -116,6 +116,7 @@ class EventManager implements EventManagerInterface
         }
 
         if (!$callable) {
+            /** @var callable $options */
             $this->_listeners[$eventKey][static::$defaultPriority][] = [
                 'callable' => $options(...),
             ];

+ 2 - 2
src/I18n/DateFormatTrait.php

@@ -321,10 +321,10 @@ trait DateFormatTrait
      * ```
      *
      * @param string $time The time string to parse.
-     * @param string|int|null $format Any format accepted by IntlDateFormatter.
+     * @param array|string|int|null $format Any format accepted by IntlDateFormatter.
      * @return static|null
      */
-    public static function parseTime(string $time, string|int|null $format = null): ?static
+    public static function parseTime(string $time, array|string|int|null $format = null): ?static
     {
         if (is_int($format)) {
             $format = [IntlDateFormatter::NONE, $format];

+ 1 - 1
src/I18n/Parser/MoFileParser.php

@@ -66,7 +66,7 @@ class MoFileParser
 
         $stat = fstat($stream);
 
-        if ($stat['size'] < self::MO_HEADER_SIZE) {
+        if ($stat === false || $stat['size'] < self::MO_HEADER_SIZE) {
             throw new CakeException('Invalid format for MO translations file');
         }
         /** @var array $magic */