Browse Source

Merge branch '4.next' into 5.x

ADmad 4 years ago
parent
commit
9df95f14e5

+ 1 - 1
composer.json

@@ -112,7 +112,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",

+ 2 - 2
phpstan-baseline.neon

@@ -116,12 +116,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 \\$class with type string\\|TObject is not subtype of native type object\\|string\\.$#"
+			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

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

+ 3 - 4
src/Error/ExceptionTrap.php

@@ -78,9 +78,11 @@ class ExceptionTrap
         // The return of this method is not defined because
         // the desired interface has bad types that will be changing in 5.x
         $request = Router::getRequest();
+        /** @var callable|class-string $class */
         $class = $this->_getConfig('exceptionRenderer');
 
         if (is_string($class)) {
+            /** @var class-string $class */
             if (!(method_exists($class, 'render') && method_exists($class, 'write'))) {
                 throw new InvalidArgumentException(
                     "Cannot use {$class} as an `exceptionRenderer`. " .
@@ -94,10 +96,7 @@ class ExceptionTrap
             return $instance;
         }
 
-        /** @var callable $factory */
-        $factory = $class;
-
-        return $factory($exception, $request);
+        return $class($exception, $request);
     }
 
     /**

+ 1 - 0
src/Error/Middleware/ErrorHandlerMiddleware.php

@@ -128,6 +128,7 @@ class ErrorHandlerMiddleware implements MiddlewareInterface
 
         try {
             $errorHandler->logException($exception, $request);
+            /** @var \Psr\Http\Message\ResponseInterface $response*/
             $response = $renderer->render();
         } catch (Throwable $internalException) {
             $errorHandler->logException($internalException, $request);

+ 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));
         }
     }

+ 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

@@ -1368,6 +1368,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);

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

@@ -57,12 +57,12 @@ 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|float|int $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
      */
-    public function format(string|float $number, array $options = []): string
+    public function format(string|float|int $number, array $options = []): string
     {
         $formatted = Number::format($number, $options);
         $options += ['escape' => true];