ソースを参照

Merge branch '4.x' into 4.next

ADmad 3 年 前
コミット
2d0abff398

+ 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 symfony/polyfill-php81 phpstan/phpstan:~1.7.0 psalm/phar:~4.23.0 && mv composer.backup composer.json",
+        "stan-setup": "cp composer.json composer.backup && composer require --dev symfony/polyfill-php81 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

@@ -26,11 +26,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
@@ -56,21 +51,11 @@ 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
@@ -81,11 +66,6 @@ parameters:
 			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/Collection/Iterator/ZipIterator.php
-
-		-
 			message: "#^Parameter \\#1 \\$iterator of method MultipleIterator\\:\\:attachIterator\\(\\) expects Iterator, Traversable given\\.$#"
 			count: 1
 			path: src/Collection/Iterator/ZipIterator.php
@@ -251,6 +231,11 @@ parameters:
 			path: src/Error/Debugger.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
@@ -396,11 +381,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
@@ -545,8 +525,3 @@ parameters:
 			count: 1
 			path: src/View/Helper/TimeHelper.php
 
-		-
-			message: "#^Constructor of class Cake\\\\Error\\\\Renderer\\\\ConsoleExceptionRenderer has an unused parameter \\$request\\.$#"
-			count: 1
-			path: src/Error/Renderer/ConsoleExceptionRenderer.php
-

+ 6 - 0
src/Error/ErrorTrap.php

@@ -200,6 +200,12 @@ class ErrorTrap
      */
     public function logger(): ErrorLoggerInterface
     {
+        $oldConfig = $this->getConfig('errorLogger');
+        if ($oldConfig !== null) {
+            deprecationWarning('The `errorLogger` configuration key is deprecated. Use `logger` instead.');
+            $this->setConfig(['logger' => $oldConfig, 'errorLogger' => null]);
+        }
+
         /** @var class-string<\Cake\Error\ErrorLoggerInterface> $class */
         $class = $this->getConfig('logger', $this->_defaultConfig['logger']);
         if (!in_array(ErrorLoggerInterface::class, class_implements($class))) {

+ 1 - 0
src/Http/ServerRequestFactory.php

@@ -243,6 +243,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 DateTime;
 use DateTimeZone;
@@ -359,6 +360,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($instance = null)
     {
-        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)) {
             /** @psalm-suppress LessSpecificReturnStatement */
             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

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

+ 8 - 0
tests/TestCase/Error/ErrorTrapTest.php

@@ -82,6 +82,14 @@ class ErrorTrapTest extends TestCase
         $this->assertInstanceOf(ErrorLogger::class, $trap->logger());
     }
 
+    public function testLoggerConfigCompatibility()
+    {
+        $this->deprecated(function () {
+            $trap = new ErrorTrap(['errorLogger' => ErrorLogger::class]);
+            $this->assertInstanceOf(ErrorLogger::class, $trap->logger());
+        });
+    }
+
     public function testLoggerHandleUnsafeOverwrite()
     {
         $trap = new ErrorTrap();

+ 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