Browse Source

Merge branch '4.next' into 5.x

ADmad 3 years ago
parent
commit
91dff0ca06

+ 1 - 1
composer.json

@@ -115,7 +115,7 @@
         ],
         "stan-tests": "phpstan.phar analyze -c tests/phpstan.neon",
         "stan-baseline": "phpstan.phar --generate-baseline",
-        "stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:~1.7.0 psalm/phar:~4.24.0 && mv composer.backup composer.json",
+        "stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:~1.8.0 psalm/phar:~4.24.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",

+ 5 - 30
phpstan-baseline.neon

@@ -11,11 +11,6 @@ parameters:
 			path: src/Cache/Engine/MemcachedEngine.php
 
 		-
-			message: "#^Parameter \\#1 \\$iterator of class LimitIterator constructor expects Iterator, Countable&Traversable\\<mixed, mixed\\> given\\.$#"
-			count: 2
-			path: src/Collection/Collection.php
-
-		-
 			message: "#^Strict comparison using \\=\\=\\= between class\\-string\\<ArrayObject\\> and 'ArrayIterator' will always evaluate to false\\.$#"
 			count: 1
 			path: src/Collection/Collection.php
@@ -41,31 +36,16 @@ parameters:
 			path: src/Collection/Iterator/TreeIterator.php
 
 		-
-			message: "#^Parameter \\#1 \\$iterator of class LimitIterator constructor expects Iterator, Countable&Traversable\\<mixed, mixed\\> given\\.$#"
-			count: 2
-			path: src/Collection/Iterator/TreeIterator.php
-
-		-
 			message: "#^Strict comparison using \\=\\=\\= between class\\-string\\<ArrayObject\\> and 'ArrayIterator' will always evaluate to false\\.$#"
 			count: 1
 			path: src/Collection/Iterator/TreeIterator.php
 
 		-
-			message: "#^Parameter \\#1 \\$iterator of class LimitIterator constructor expects Iterator, Countable&Traversable\\<mixed, mixed\\> given\\.$#"
-			count: 2
-			path: src/Collection/Iterator/TreePrinter.php
-
-		-
 			message: "#^Strict comparison using \\=\\=\\= between class\\-string\\<ArrayObject\\> and 'ArrayIterator' will always evaluate to false\\.$#"
 			count: 1
 			path: src/Collection/Iterator/TreePrinter.php
 
 		-
-			message: "#^Parameter \\#1 \\$iterator of class LimitIterator constructor expects Iterator, Countable&Traversable\\<mixed, mixed\\> given\\.$#"
-			count: 2
-			path: src/Collection/Iterator/ZipIterator.php
-
-		-
 			message: "#^Strict comparison using \\=\\=\\= between class\\-string\\<ArrayObject\\> and 'ArrayIterator' will always evaluate to false\\.$#"
 			count: 1
 			path: src/Collection/Iterator/ZipIterator.php
@@ -141,11 +121,6 @@ parameters:
 			path: src/Database/Expression/QueryExpression.php
 
 		-
-			message: "#^Constructor of class Cake\\\\Error\\\\Renderer\\\\ConsoleExceptionRenderer has an unused parameter \\$request\\.$#"
-			count: 1
-			path: src/Error/Renderer/ConsoleExceptionRenderer.php
-
-		-
 			message: "#^PHPDoc tag @param for parameter \\$subject with type TSubject\\|null is not subtype of native type object\\|null\\.$#"
 			count: 1
 			path: src/Event/Event.php
@@ -161,6 +136,11 @@ parameters:
 			path: src/Event/Event.php
 
 		-
+			message: "#^Constructor of class Cake\\\\Error\\\\Renderer\\\\ConsoleExceptionRenderer has an unused parameter \\$request\\.$#"
+			count: 1
+			path: src/Error/Renderer/ConsoleExceptionRenderer.php
+
+		-
 			message: "#^Unsafe usage of new static\\(\\)\\.$#"
 			count: 1
 			path: src/Event/EventManager.php
@@ -256,11 +236,6 @@ parameters:
 			path: src/ORM/Query.php
 
 		-
-			message: "#^Parameter \\#1 \\$iterator of class LimitIterator constructor expects Iterator, Countable&Traversable\\<mixed, mixed\\> given\\.$#"
-			count: 2
-			path: src/ORM/ResultSet.php
-
-		-
 			message: "#^Strict comparison using \\=\\=\\= between class\\-string\\<ArrayObject\\> and 'ArrayIterator' will always evaluate to false\\.$#"
 			count: 1
 			path: src/ORM/ResultSet.php

+ 1 - 0
src/Http/ServerRequestFactory.php

@@ -225,6 +225,7 @@ abstract class ServerRequestFactory implements ServerRequestFactoryInterface
      */
     protected static function marshalUriFromSapi(array $server, array $headers): UriInterface
     {
+        /** @psalm-suppress DeprecatedFunction */
         $uri = marshalUriFromSapi($server, $headers);
         [$base, $webroot] = static::getBase($uri, $server);
 

+ 4 - 0
src/I18n/DateFormatTrait.php

@@ -17,6 +17,7 @@ declare(strict_types=1);
 namespace Cake\I18n;
 
 use Cake\Chronos\DifferenceFormatterInterface;
+use Cake\Core\Exception\CakeException;
 use Closure;
 use DateTimeImmutable;
 use DateTimeInterface;
@@ -383,6 +384,9 @@ trait DateFormatTrait
             null,
             $pattern
         );
+        if (!$formatter) {
+            throw new CakeException('Unable to create IntlDateFormatter instance');
+        }
         $formatter->setLenient(static::$lenientParsing);
 
         $time = $formatter->parse($time);

+ 4 - 6
src/Utility/Security.php

@@ -163,18 +163,16 @@ class Security
      */
     public static function engine(?OpenSsl $instance = null): OpenSsl
     {
-        if ($instance === null && static::$_instance === null) {
-            if (extension_loaded('openssl')) {
-                $instance = new OpenSsl();
-            }
-        }
         if ($instance) {
-            static::$_instance = $instance;
+            return static::$_instance = $instance;
         }
         if (isset(static::$_instance)) {
             /** @var \Cake\Utility\Crypto\OpenSsl */
             return static::$_instance;
         }
+        if (extension_loaded('openssl')) {
+            return static::$_instance = new OpenSsl();
+        }
         throw new InvalidArgumentException(
             'No compatible crypto engine available. ' .
             'Load the openssl extension.'

+ 1 - 1
src/Utility/Text.php

@@ -53,7 +53,7 @@ class Text
      * Generate a random UUID version 4
      *
      * Warning: This method should not be used as a random seed for any cryptographic operations.
-     * Instead, you should use the openssl or mcrypt extensions.
+     * Instead, you should use `Security::randomBytes()` or `Security::randomString()` instead.
      *
      * It should also not be used to create identifiers that have security implications, such as
      * 'unguessable' URL identifiers. Instead, you should use {@link \Cake\Utility\Security::randomBytes()}` for that.

+ 6 - 0
tests/TestCase/Database/ConnectionTest.php

@@ -988,6 +988,9 @@ class ConnectionTest extends TestCase
                     return false;
                 });
                 $this->rollbackSourceLine = __LINE__ - 1;
+                if (PHP_VERSION_ID >= 80200) {
+                    $this->rollbackSourceLine -= 2;
+                }
 
                 return true;
             });
@@ -1026,6 +1029,9 @@ class ConnectionTest extends TestCase
                         return false;
                     });
                     $this->rollbackSourceLine = __LINE__ - 1;
+                    if (PHP_VERSION_ID >= 80200) {
+                        $this->rollbackSourceLine -= 2;
+                    }
 
                     $this->pushNestedTransactionState();
 

+ 14 - 14
tests/TestCase/Utility/SecurityTest.php

@@ -28,6 +28,20 @@ use RuntimeException;
 class SecurityTest extends TestCase
 {
     /**
+     * Test engine
+     */
+    public function testEngineEquivalence(): void
+    {
+        $restore = Security::engine();
+        $newEngine = new OpenSsl();
+
+        Security::engine($newEngine);
+
+        $this->assertSame($newEngine, Security::engine());
+        $this->assertNotSame($restore, Security::engine());
+    }
+
+    /**
      * testHash method
      */
     public function testHash(): void
@@ -186,20 +200,6 @@ class SecurityTest extends TestCase
     }
 
     /**
-     * Test engine
-     */
-    public function testEngineEquivalence(): void
-    {
-        $restore = Security::engine();
-        $newEngine = new OpenSsl();
-
-        Security::engine($newEngine);
-
-        $this->assertSame($newEngine, Security::engine());
-        $this->assertNotSame($restore, Security::engine());
-    }
-
-    /**
      * Tests that the salt can be set and retrieved
      */
     public function testSalt(): void