Browse Source

Merge pull request #16271 from cakephp/stan

Bump up phpstan and psalm's version.
ADmad 4 years ago
parent
commit
02b3cb7efe

+ 1 - 1
composer.json

@@ -114,7 +114,7 @@
             "@psalm"
         ],
         "stan-tests": "phpstan.phar analyze -c tests/phpstan.neon",
-        "stan-setup": "cp composer.json composer.backup && composer require --dev symfony/polyfill-php81 phpstan/phpstan:~1.0.0 psalm/phar:~4.11.0 && mv composer.backup composer.json",
+        "stan-setup": "cp composer.json composer.backup && composer require --dev symfony/polyfill-php81 phpstan/phpstan:~1.4.0 psalm/phar:~4.19.0 && mv composer.backup composer.json",
         "lowest": "validate-prefer-lowest",
         "lowest-setup": "composer update --prefer-lowest --prefer-stable --prefer-dist --no-interaction && cp composer.json composer.backup && composer require --dev dereuromark/composer-prefer-lowest && mv composer.backup composer.json",
         "test": "phpunit",

+ 7 - 2
phpstan-baseline.neon

@@ -11,6 +11,11 @@ parameters:
 			path: src/Auth/Storage/SessionStorage.php
 
 		-
+			message: "#^PHPDoc tag @mixin contains invalid type Cake\\\\Core\\\\InstanceConfigTrait\\.$#"
+			count: 1
+			path: src/Auth/Storage/StorageInterface.php
+
+		-
 			message: "#^Access to undefined constant Memcached\\:\\:DYNAMIC_CLIENT_MODE\\.$#"
 			count: 1
 			path: src/Cache/Engine/MemcachedEngine.php
@@ -176,12 +181,12 @@ parameters:
 			path: src/Controller/ControllerFactory.php
 
 		-
-			message: "#^Array \\(array\\<TObject\\>\\) does not accept object\\.$#"
+			message: "#^PHPDoc tag @param for parameter \\$object with type TObject is not subtype of native type object\\.$#"
 			count: 1
 			path: src/Core/ObjectRegistry.php
 
 		-
-			message: "#^PHPDoc tag @param for parameter \\$object with type TObject is not subtype of native type object\\.$#"
+			message: "#^Property Cake\\\\Core\\\\ObjectRegistry\\<TObject\\>\\:\\:\\$_loaded \\(array\\<TObject\\>\\) does not accept array\\<object\\|TObject\\>\\.$#"
 			count: 1
 			path: src/Core/ObjectRegistry.php
 

+ 1 - 0
psalm.xml

@@ -28,6 +28,7 @@
             <errorLevel type="suppress">
                 <referencedClass name="Memcached"/>
                 <referencedClass name="Redis"/>
+                <referencedClass name="RedisException"/>
             </errorLevel>
         </UndefinedClass>
         <UndefinedDocblockClass>

+ 2 - 0
src/Http/Session.php

@@ -481,6 +481,7 @@ class Session
         }
         $value = $this->read($name);
         if ($value !== null) {
+            /** @psalm-suppress InvalidScalarArgument */
             $this->_overwrite($_SESSION, Hash::remove($_SESSION, $name));
         }
 
@@ -545,6 +546,7 @@ class Session
     public function delete(string $name): void
     {
         if ($this->check($name)) {
+            /** @psalm-suppress InvalidScalarArgument */
             $this->_overwrite($_SESSION, Hash::remove($_SESSION, $name));
         }
     }

+ 1 - 1
src/I18n/Number.php

@@ -159,7 +159,7 @@ class Number
      * - `before` - The string to place before whole numbers, e.g. '['
      * - `after` - The string to place after decimal numbers, e.g. ']'
      *
-     * @param string|float $value A floating point number.
+     * @param string|int|float $value A floating point number.
      * @param array<string, mixed> $options An array with options.
      * @return string Formatted number
      */

+ 2 - 1
src/TestSuite/Constraint/Session/FlashParamEquals.php

@@ -80,9 +80,10 @@ class FlashParamEquals extends Constraint
         // Server::run calls Session::close at the end of the request.
         // Which means, that we cannot use Session object here to access the session data.
         // Call to Session::read will start new session (and will erase the data).
-
+        /** @psalm-suppress InvalidScalarArgument */
         $messages = (array)Hash::get($_SESSION, 'Flash.' . $this->key);
         if ($this->at) {
+            /** @psalm-suppress InvalidScalarArgument */
             $messages = [Hash::get($_SESSION, 'Flash.' . $this->key . '.' . $this->at)];
         }
 

+ 1 - 0
src/TestSuite/Constraint/Session/SessionEquals.php

@@ -51,6 +51,7 @@ class SessionEquals extends Constraint
         // Server::run calls Session::close at the end of the request.
         // Which means, that we cannot use Session object here to access the session data.
         // Call to Session::read will start new session (and will erase the data).
+        /** @psalm-suppress InvalidScalarArgument */
         return Hash::get($_SESSION, $this->path) === $other;
     }
 

+ 1 - 0
src/TestSuite/Constraint/Session/SessionHasKey.php

@@ -51,6 +51,7 @@ class SessionHasKey extends Constraint
         // Server::run calls Session::close at the end of the request.
         // Which means, that we cannot use Session object here to access the session data.
         // Call to Session::read will start new session (and will erase the data).
+        /** @psalm-suppress InvalidScalarArgument */
         return Hash::check($_SESSION, $this->path) === true;
     }
 

+ 1 - 0
src/TestSuite/IntegrationTestTrait.php

@@ -1363,6 +1363,7 @@ trait IntegrationTestTrait
      */
     protected function getSession(): TestSession
     {
+        /** @psalm-suppress InvalidScalarArgument */
         return new TestSession($_SESSION);
     }
 }

+ 1 - 0
src/Utility/Security.php

@@ -110,6 +110,7 @@ class Security
      */
     public static function randomBytes(int $length): string
     {
+        /** @psalm-suppress ArgumentTypeCoercion */
         return random_bytes($length);
     }
 

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

@@ -123,13 +123,14 @@ class EntityContext implements ContextInterface
     {
         /** @var \Cake\ORM\Table|null $table */
         $table = $this->_context['table'];
-        /** @var \Cake\Datasource\EntityInterface|iterable $entity */
+        /** @var \Cake\Datasource\EntityInterface|iterable<\Cake\Datasource\EntityInterface|array> $entity */
         $entity = $this->_context['entity'];
 
         $this->_isCollection = is_iterable($entity);
 
         if (empty($table)) {
             if ($this->_isCollection) {
+                /** @var iterable<\Cake\Datasource\EntityInterface|array> $entity */
                 foreach ($entity as $e) {
                     $entity = $e;
                     break;
@@ -141,6 +142,7 @@ class EntityContext implements ContextInterface
                 /** @psalm-suppress PossiblyInvalidMethodCall */
                 $table = $entity->getSource();
             }
+            /** @psalm-suppress PossiblyInvalidArgument */
             if (!$table && $isEntity && get_class($entity) !== Entity::class) {
                 [, $entityClass] = namespaceSplit(get_class($entity));
                 $table = Inflector::pluralize($entityClass);

+ 1 - 1
src/View/Helper/NumberHelper.php

@@ -146,7 +146,7 @@ class NumberHelper extends Helper
      * - `after` - The string to place after decimal numbers, e.g. ']'
      * - `escape` - Whether to escape html in resulting string
      *
-     * @param string|float $number A floating point number.
+     * @param string|int|float $number A floating point number.
      * @param array<string, mixed> $options An array with options.
      * @return string Formatted number
      * @link https://book.cakephp.org/4/en/views/helpers/number.html#formatting-numbers