Browse Source

Merge pull request #14137 from cakephp/fix-psalm-warnings

Fixed new psalm warnings
ADmad 6 years ago
parent
commit
cc9b263699

+ 1 - 1
composer.json

@@ -110,7 +110,7 @@
             "@phpstan",
             "@psalm"
         ],
-        "stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^0.12.0 psalm/phar:^3.7 && mv composer.backup composer.json"
+        "stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^0.12.0 psalm/phar:~3.8.0 && mv composer.backup composer.json"
     },
     "config": {
         "sort-packages": true,

+ 1 - 1
src/Database/Statement/PDOStatement.php

@@ -96,7 +96,7 @@ class PDOStatement extends StatementDecorator
      * ```
      *
      * @param string|int $type 'num' for positional columns, assoc for named columns
-     * @return array|false Result array containing columns and values or false if no results
+     * @return mixed Result array containing columns and values or false if no results
      * are left
      */
     public function fetch($type = parent::FETCH_TYPE_NUM)

+ 1 - 1
src/Database/Statement/StatementDecorator.php

@@ -192,7 +192,7 @@ class StatementDecorator implements StatementInterface, Countable, IteratorAggre
      * ```
      *
      * @param string|int $type 'num' for positional columns, assoc for named columns
-     * @return array|false Result array containing columns and values or false if no results
+     * @return mixed Result array containing columns and values or false if no results
      * are left
      */
     public function fetch($type = self::FETCH_TYPE_NUM)

+ 1 - 1
src/Database/StatementInterface.php

@@ -131,7 +131,7 @@ interface StatementInterface
      * ```
      *
      * @param string|int $type 'num' for positional columns, assoc for named columns, or PDO fetch mode constants.
-     * @return array|false Result array containing columns and values or false if no results
+     * @return mixed Result array containing columns and values or false if no results
      * are left
      */
     public function fetch($type = 'num');

+ 1 - 1
src/Http/Response.php

@@ -1087,7 +1087,7 @@ class Response implements ResponseInterface
         } elseif (is_int($time)) {
             $result = new DateTime(date('Y-m-d H:i:s', $time));
         } else {
-            $result = new DateTime($time);
+            $result = new DateTime($time ?? 'now');
         }
 
         /** @psalm-suppress UndefinedInterfaceMethod */

+ 2 - 1
src/Log/Log.php

@@ -358,7 +358,8 @@ class Log
         }
 
         if (!in_array($level, static::$_levels, true)) {
-            throw new InvalidArgumentException(sprintf('Invalid log level "%s"', $level));
+            /** @psalm-suppress PossiblyFalseArgument */
+            throw new InvalidArgumentException(sprintf('Invalid log level `%s`', $level));
         }
 
         $logged = false;

+ 1 - 1
src/ORM/Marshaller.php

@@ -96,7 +96,7 @@ class Marshaller
                 if (substr($key, 0, 1) !== '_') {
                     throw new InvalidArgumentException(sprintf(
                         'Cannot marshal data for "%s" association. It is not associated with "%s".',
-                        $key,
+                        (string)$key,
                         $this->_table->getAlias()
                     ));
                 }

+ 2 - 2
src/Utility/Xml.php

@@ -318,7 +318,7 @@ class Xml
                     $isNamespace = strpos($key, 'xmlns:');
                     if ($isNamespace !== false) {
                         /** @psalm-suppress PossiblyUndefinedMethod */
-                        $node->setAttributeNS('http://www.w3.org/2000/xmlns/', $key, $value);
+                        $node->setAttributeNS('http://www.w3.org/2000/xmlns/', $key, (string)$value);
                         continue;
                     }
                     if ($key[0] !== '@' && $format === 'tags') {
@@ -327,7 +327,7 @@ class Xml
                             // https://www.w3.org/TR/REC-xml/#syntax
                             // https://bugs.php.net/bug.php?id=36795
                             $child = $dom->createElement($key, '');
-                            $child->appendChild(new DOMText($value));
+                            $child->appendChild(new DOMText((string)$value));
                         } else {
                             $child = $dom->createElement($key, (string)$value);
                         }

+ 1 - 1
src/View/Form/EntityContext.php

@@ -658,11 +658,11 @@ class EntityContext implements ContextInterface
         }
 
         $table = $this->_tables[$this->_rootName];
-        /** @var \Cake\ORM\Association\BelongsToMany|null $assoc */
         $assoc = null;
         foreach ($normalized as $part) {
             if ($part === '_joinData') {
                 if ($assoc) {
+                    /** @var \Cake\ORM\Association\BelongsToMany $assoc */
                     $table = $assoc->junction();
                     $assoc = null;
                     continue;