Browse Source

Merge pull request #15347 from cakephp/stan

Update psalm and phpstan's version.
ADmad 5 years ago
parent
commit
da54b1c75e

+ 1 - 1
composer.json

@@ -108,7 +108,7 @@
             "@phpstan",
             "@psalm"
         ],
-        "stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:0.12.58 psalm/phar:~4.3.0 && mv composer.backup composer.json",
+        "stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:0.12.79 psalm/phar:~4.6.2 && mv composer.backup composer.json",
         "test": "phpunit",
         "test-coverage": "phpunit --coverage-clover=clover.xml"
     },

+ 21 - 21
phpstan-baseline.neon

@@ -31,12 +31,12 @@ parameters:
 			path: src/Cache/Engine/MemcachedEngine.php
 
 		-
-			message: "#^Parameter \\#1 \\$iterator of class LimitIterator constructor expects Iterator, Countable&Traversable given\\.$#"
+			message: "#^Parameter \\#1 \\$iterator of class LimitIterator constructor expects Iterator, Countable&Traversable\\<mixed, mixed\\> given\\.$#"
 			count: 2
 			path: src/Collection/Collection.php
 
 		-
-			message: "#^Parameter \\#1 \\$it of method AppendIterator\\:\\:append\\(\\) expects Iterator, Traversable given\\.$#"
+			message: "#^Parameter \\#1 \\$iterator of method AppendIterator\\:\\:append\\(\\) expects Iterator, Traversable given\\.$#"
 			count: 2
 			path: src/Collection/Collection.php
 
@@ -46,12 +46,12 @@ parameters:
 			path: src/Collection/Collection.php
 
 		-
-			message: "#^Parameter \\#1 \\$iterator of class LimitIterator constructor expects Iterator, Countable&Traversable given\\.$#"
+			message: "#^Parameter \\#1 \\$iterator of class LimitIterator constructor expects Iterator, Countable&Traversable\\<mixed, mixed\\> given\\.$#"
 			count: 2
 			path: src/Collection/Iterator/TreeIterator.php
 
 		-
-			message: "#^Parameter \\#1 \\$it of method AppendIterator\\:\\:append\\(\\) expects Iterator, Traversable given\\.$#"
+			message: "#^Parameter \\#1 \\$iterator of method AppendIterator\\:\\:append\\(\\) expects Iterator, Traversable given\\.$#"
 			count: 2
 			path: src/Collection/Iterator/TreeIterator.php
 
@@ -61,12 +61,12 @@ parameters:
 			path: src/Collection/Iterator/TreeIterator.php
 
 		-
-			message: "#^Parameter \\#1 \\$iterator of class LimitIterator constructor expects Iterator, Countable&Traversable given\\.$#"
+			message: "#^Parameter \\#1 \\$iterator of class LimitIterator constructor expects Iterator, Countable&Traversable\\<mixed, mixed\\> given\\.$#"
 			count: 2
 			path: src/Collection/Iterator/TreePrinter.php
 
 		-
-			message: "#^Parameter \\#1 \\$it of method AppendIterator\\:\\:append\\(\\) expects Iterator, Traversable given\\.$#"
+			message: "#^Parameter \\#1 \\$iterator of method AppendIterator\\:\\:append\\(\\) expects Iterator, Traversable given\\.$#"
 			count: 2
 			path: src/Collection/Iterator/TreePrinter.php
 
@@ -76,17 +76,17 @@ parameters:
 			path: src/Collection/Iterator/TreePrinter.php
 
 		-
-			message: "#^Parameter \\#1 \\$iterator of class LimitIterator constructor expects Iterator, Countable&Traversable given\\.$#"
+			message: "#^Parameter \\#1 \\$iterator of class LimitIterator constructor expects Iterator, Countable&Traversable\\<mixed, mixed\\> given\\.$#"
 			count: 2
 			path: src/Collection/Iterator/ZipIterator.php
 
 		-
-			message: "#^Parameter \\#1 \\$it of method AppendIterator\\:\\:append\\(\\) expects Iterator, Traversable given\\.$#"
+			message: "#^Parameter \\#1 \\$iterator of method AppendIterator\\:\\:append\\(\\) expects Iterator, Traversable given\\.$#"
 			count: 2
 			path: src/Collection/Iterator/ZipIterator.php
 
 		-
-			message: "#^Method Cake\\\\Collection\\\\Iterator\\\\ZipIterator\\:\\:toArray\\(\\) should return array but returns array\\<array, array\\|false\\>\\.$#"
+			message: "#^Method Cake\\\\Collection\\\\Iterator\\\\ZipIterator\\:\\:toArray\\(\\) should return array but returns array\\<array, array\\>\\.$#"
 			count: 1
 			path: src/Collection/Iterator/ZipIterator.php
 
@@ -96,12 +96,17 @@ parameters:
 			path: src/Collection/Iterator/ZipIterator.php
 
 		-
-			message: "#^Parameter \\#1 \\$iterator of class LimitIterator constructor expects Iterator, Countable&Traversable given\\.$#"
+			message: "#^Parameter \\#1 \\$iterator of method MultipleIterator\\:\\:attachIterator\\(\\) expects Iterator, Traversable given\\.$#"
+			count: 1
+			path: src/Collection/Iterator/ZipIterator.php
+
+		-
+			message: "#^Parameter \\#1 \\$iterator of class LimitIterator constructor expects Iterator, Countable&Traversable\\<mixed, mixed\\> given\\.$#"
 			count: 2
 			path: src/ORM/ResultSet.php
 
 		-
-			message: "#^Parameter \\#1 \\$it of method AppendIterator\\:\\:append\\(\\) expects Iterator, Traversable given\\.$#"
+			message: "#^Parameter \\#1 \\$iterator of method AppendIterator\\:\\:append\\(\\) expects Iterator, Traversable given\\.$#"
 			count: 2
 			path: src/ORM/ResultSet.php
 
@@ -251,11 +256,6 @@ parameters:
 			path: src/ORM/Table.php
 
 		-
-			message: "#^Variable \\$entities in PHPDoc tag @var does not match any variable in the foreach loop\\: \\$key, \\$entity$#"
-			count: 1
-			path: src/ORM/Table.php
-
-		-
 			message: "#^Cannot unset offset 'args' on array\\('path' \\=\\> string, 'reference' \\=\\> mixed\\)\\.$#"
 			count: 1
 			path: src/Error/Debugger.php
@@ -366,11 +366,6 @@ parameters:
 			path: src/I18n/Time.php
 
 		-
-			message: "#^Access to undefined constant NumberFormatter\\:\\:CURRENCY_ACCOUNTING\\.$#"
-			count: 1
-			path: src/I18n/Number.php
-
-		-
 			message: "#^Offset 1 does not exist on array\\(\\)\\|array\\(0 \\=\\> 'context'\\|'ids'\\|'translated', \\?1 \\=\\> 'plural'\\|'singular'\\|int\\)\\.$#"
 			count: 1
 			path: src/I18n/Parser/PoFileParser.php
@@ -441,6 +436,11 @@ parameters:
 			path: src/TestSuite/ConsoleIntegrationTestCase.php
 
 		-
+			message: "#^PHPDoc tag @template TCode for class Cake\\\\TestSuite\\\\Constraint\\\\Response\\\\StatusCodeBase with bound type array\\<int, int\\> is not supported\\.$#"
+			count: 1
+			path: src/TestSuite/Constraint/Response/StatusCodeBase.php
+
+		-
 			message: "#^Access to an undefined property PHPUnit\\\\Framework\\\\Test\\:\\:\\$fixtureManager\\.$#"
 			count: 1
 			path: src/TestSuite/Fixture/FixtureInjector.php

+ 91 - 9
psalm-baseline.xml

@@ -1,12 +1,40 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<files psalm-version="4.3.1@2feba22a005a18bf31d4c7b9bdb9252c73897476">
+<files psalm-version="4.x-dev@">
   <file src="src/Collection/CollectionTrait.php">
-    <ArgumentTypeCoercion occurrences="4">
+    <ArgumentTypeCoercion occurrences="2">
       <code>$iterator</code>
       <code>$iterator</code>
-      <code>$this-&gt;newCollection($items)-&gt;unwrap()</code>
-      <code>$this-&gt;unwrap()</code>
     </ArgumentTypeCoercion>
+    <MissingParamType occurrences="28">
+      <code>$callback</code>
+      <code>$condition</code>
+      <code>$groupPath</code>
+      <code>$idPath</code>
+      <code>$initial</code>
+      <code>$item</code>
+      <code>$item</code>
+      <code>$items</code>
+      <code>$items</code>
+      <code>$key</code>
+      <code>$key</code>
+      <code>$keyPath</code>
+      <code>$nestingKey</code>
+      <code>$order</code>
+      <code>$parentPath</code>
+      <code>$path</code>
+      <code>$path</code>
+      <code>$path</code>
+      <code>$path</code>
+      <code>$path</code>
+      <code>$path</code>
+      <code>$path</code>
+      <code>$path</code>
+      <code>$path</code>
+      <code>$path</code>
+      <code>$value</code>
+      <code>$valuePath</code>
+      <code>$values</code>
+    </MissingParamType>
   </file>
   <file src="src/Collection/Iterator/ZipIterator.php">
     <ArgumentTypeCoercion occurrences="1">
@@ -74,6 +102,19 @@
       <code>$value</code>
     </InvalidScalarArgument>
   </file>
+  <file src="src/Database/Query.php">
+    <InvalidArgument occurrences="1"/>
+  </file>
+  <file src="src/Database/Schema/MysqlSchemaDialect.php">
+    <NonInvariantDocblockPropertyType occurrences="1">
+      <code>$_driver</code>
+    </NonInvariantDocblockPropertyType>
+  </file>
+  <file src="src/Database/Statement/PDOStatement.php">
+    <NonInvariantDocblockPropertyType occurrences="1">
+      <code>$_statement</code>
+    </NonInvariantDocblockPropertyType>
+  </file>
   <file src="src/Datasource/ModelAwareTrait.php">
     <DeprecatedClass occurrences="1">
       <code>$this</code>
@@ -104,6 +145,11 @@
       <code>$time</code>
     </ArgumentTypeCoercion>
   </file>
+  <file src="src/I18n/DateFormatTrait.php">
+    <MissingParamType occurrences="1">
+      <code>$format</code>
+    </MissingParamType>
+  </file>
   <file src="src/I18n/FrozenDate.php">
     <ArgumentTypeCoercion occurrences="1">
       <code>$time</code>
@@ -131,6 +177,11 @@
       <code>$this</code>
     </DeprecatedClass>
   </file>
+  <file src="src/ORM/Locator/TableLocator.php">
+    <NonInvariantDocblockPropertyType occurrences="1">
+      <code>$instances</code>
+    </NonInvariantDocblockPropertyType>
+  </file>
   <file src="src/ORM/Marshaller.php">
     <ArgumentTypeCoercion occurrences="2">
       <code>$assoc</code>
@@ -153,17 +204,42 @@
       <code>Shell</code>
     </DeprecatedClass>
   </file>
-  <file src="src/TestSuite/ContainerStubTrait.php">
-    <DeprecatedClass occurrences="2">
-      <code>$this</code>
-    </DeprecatedClass>
-  </file>
   <file src="src/TestSuite/Constraint/EventFired.php">
     <InternalClass occurrences="1"/>
   </file>
   <file src="src/TestSuite/Constraint/EventFiredWith.php">
     <InternalClass occurrences="2"/>
   </file>
+  <file src="src/TestSuite/Constraint/Response/ContentType.php">
+    <NonInvariantDocblockPropertyType occurrences="1">
+      <code>$response</code>
+    </NonInvariantDocblockPropertyType>
+  </file>
+  <file src="src/TestSuite/Constraint/Response/CookieEncryptedEquals.php">
+    <NonInvariantDocblockPropertyType occurrences="1">
+      <code>$response</code>
+    </NonInvariantDocblockPropertyType>
+  </file>
+  <file src="src/TestSuite/Constraint/Response/CookieEquals.php">
+    <NonInvariantDocblockPropertyType occurrences="1">
+      <code>$response</code>
+    </NonInvariantDocblockPropertyType>
+  </file>
+  <file src="src/TestSuite/Constraint/Response/CookieSet.php">
+    <NonInvariantDocblockPropertyType occurrences="1">
+      <code>$response</code>
+    </NonInvariantDocblockPropertyType>
+  </file>
+  <file src="src/TestSuite/Constraint/Response/FileSent.php">
+    <NonInvariantDocblockPropertyType occurrences="1">
+      <code>$response</code>
+    </NonInvariantDocblockPropertyType>
+  </file>
+  <file src="src/TestSuite/Constraint/Response/FileSentAs.php">
+    <NonInvariantDocblockPropertyType occurrences="1">
+      <code>$response</code>
+    </NonInvariantDocblockPropertyType>
+  </file>
   <file src="src/TestSuite/Constraint/Response/ResponseBase.php">
     <InternalClass occurrences="1">
       <code>new AssertionFailedError('No response set, cannot assert content.')</code>
@@ -174,6 +250,12 @@
       <code>new AssertionFailedError($message)</code>
     </InternalClass>
   </file>
+  <file src="src/TestSuite/ContainerStubTrait.php">
+    <DeprecatedClass occurrences="2">
+      <code>$this</code>
+      <code>$this</code>
+    </DeprecatedClass>
+  </file>
   <file src="src/TestSuite/Fixture/FixtureInjector.php">
     <DeprecatedInterface occurrences="1">
       <code>FixtureInjector</code>

+ 1 - 1
src/Collection/Iterator/ZipIterator.php

@@ -88,7 +88,7 @@ class ZipIterator extends MultipleIterator implements CollectionInterface, Seria
      * Returns the value resulting out of zipping all the elements for all the
      * iterators with the same positional index.
      *
-     * @return array|false
+     * @return array
      */
     public function current()
     {

+ 2 - 0
src/Console/ConsoleInput.php

@@ -92,6 +92,8 @@ class ConsoleInput
         $error = null;
         set_error_handler(function (int $code, string $message) use (&$error) {
             $error = "stream_select failed with code={$code} message={$message}.";
+
+            return true;
         });
         $readyFds = stream_select($readFds, $writeFds, $errorFds, $timeout);
         restore_error_handler();

+ 1 - 0
src/Database/Expression/TupleComparison.php

@@ -30,6 +30,7 @@ class TupleComparison extends ComparisonExpression
      * The type to be used for casting the value to a database representation
      *
      * @var array
+     * @psalm-suppress NonInvariantDocblockPropertyType
      */
     protected $_type;
 

+ 0 - 1
src/Error/BaseErrorHandler.php

@@ -311,7 +311,6 @@ abstract class BaseErrorHandler
         );
         $context = [];
         if (!empty($this->_config['trace'])) {
-            /** @var string $trace */
             $context['trace'] = Debugger::trace([
                 'start' => 1,
                 'format' => 'log',

+ 2 - 0
src/Http/MiddlewareQueue.php

@@ -31,6 +31,8 @@ use SeekableIterator;
 /**
  * Provides methods for creating and manipulating a "queue" of middlewares.
  * This queue is used to process a request and generate response via \Cake\Http\Runner.
+ *
+ * @template-implements \SeekableIterator<int, \Psr\Http\Server\MiddlewareInterface>
  */
 class MiddlewareQueue implements Countable, SeekableIterator
 {

+ 1 - 1
src/Http/Session.php

@@ -509,7 +509,7 @@ class Session
             $data = Hash::insert($data, $key, $val);
         }
 
-        /** @psalm-suppress NullReference */
+        /** @psalm-suppress PossiblyNullArgument */
         $this->_overwrite($_SESSION, $data);
     }
 

+ 1 - 1
src/ORM/Locator/LocatorAwareTrait.php

@@ -51,7 +51,7 @@ trait LocatorAwareTrait
     public function getTableLocator(): LocatorInterface
     {
         if ($this->_tableLocator === null) {
-            /** @var \Cake\ORM\Locator\LocatorInterface $this->_tableLocator */
+            /** @psalm-suppress InvalidPropertyAssignmentValue */
             $this->_tableLocator = FactoryLocator::get('Table');
         }
 

+ 1 - 1
src/ORM/Locator/TableLocator.php

@@ -48,7 +48,7 @@ class TableLocator extends AbstractLocator implements LocatorInterface
     /**
      * Instances that belong to the registry.
      *
-     * @var \Cake\ORM\Table[]
+     * @var array<string, \Cake\ORM\Table>
      */
     protected $instances = [];
 

+ 2 - 1
src/ORM/Marshaller.php

@@ -669,8 +669,9 @@ class Marshaller
             })
             ->toArray();
 
+        /** @psalm-suppress InvalidArrayOffset */
         $new = $indexed[null] ?? [];
-        /** @psalm-suppress PossiblyNullArrayOffset */
+        /** @psalm-suppress InvalidArrayOffset */
         unset($indexed[null]);
         $output = [];
 

+ 1 - 0
src/Routing/Route/Route.php

@@ -295,6 +295,7 @@ class Route
             $this->_writeRoute();
         }
 
+        /** @var string */
         return $this->_compiledRoute;
     }
 

+ 2 - 0
src/TestSuite/Constraint/Response/StatusCodeBase.php

@@ -19,11 +19,13 @@ namespace Cake\TestSuite\Constraint\Response;
  * StatusCodeBase
  *
  * @internal
+ * @template TCode as int|array<int, int>
  */
 abstract class StatusCodeBase extends ResponseBase
 {
     /**
      * @var int|array
+     * @psalm-var TCode
      */
     protected $code;
 

+ 1 - 0
src/TestSuite/Constraint/Response/StatusSuccess.php

@@ -19,6 +19,7 @@ namespace Cake\TestSuite\Constraint\Response;
  * StatusSuccess
  *
  * @internal
+ * @extends \Cake\TestSuite\Constraint\Response\StatusCodeBase<array<int, int>>
  */
 class StatusSuccess extends StatusCodeBase
 {

+ 1 - 0
src/Utility/Xml.php

@@ -472,6 +472,7 @@ class Xml
             }
 
             foreach ($xml->children($namespace, true) as $child) {
+                /** @psalm-suppress PossiblyNullArgument */
                 static::_toArray($child, $data, $namespace, $namespaces);
             }
         }

+ 1 - 2
src/View/JsonView.php

@@ -94,8 +94,7 @@ class JsonView extends SerializedView
      *   - Setting it to a string value, uses the provided query string parameter
      *     for finding the JSONP callback name.
      *
-     * @var array
-     * @pslam-var array{serialize:string|bool|null, jsonOptions: int|null, jsonp: bool|string|null}
+     * @var array<string, mixed>
      */
     protected $_defaultConfig = [
         'serialize' => null,

+ 1 - 2
src/View/SerializedView.php

@@ -42,8 +42,7 @@ abstract class SerializedView extends View
      *   names. If true all view variables will be serialized. If null or false
      *   normal view template will be rendered.
      *
-     * @var array
-     * @psalm-var array{serialize:string|bool|null}
+     * @var array<string, mixed>
      */
     protected $_defaultConfig = [
         'serialize' => null,

+ 1 - 1
src/View/View.php

@@ -223,7 +223,7 @@ class View implements EventDispatcherInterface
     /**
      * Default custom config options.
      *
-     * @var string[]
+     * @var array<string, mixed>
      */
     protected $_defaultConfig = [];
 

+ 1 - 2
src/View/XmlView.php

@@ -103,8 +103,7 @@ class XmlView extends SerializedView
      *   For e.g. 'format' as 'attributes' instead of 'tags'.
      * - `rootNode`: Root node name. Defaults to "response".
      *
-     * @var array
-     * @psalm-var array{serialize:string|bool|null, xmlOptions: int|null, rootNode: string|null}
+     * @var array<string, mixed>
      */
     protected $_defaultConfig = [
         'serialize' => null,