Browse Source

Merge pull request #17172 from cakephp/5.x-fixes

5.x fixes
ADmad 2 years ago
parent
commit
131e379584

+ 2 - 2
.phive/phars.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <phive xmlns="https://phar.io/phive">
-  <phar name="phpstan" version="1.10.14" installed="1.10.14" location="./tools/phpstan" copy="false"/>
-  <phar name="psalm" version="5.10.0" installed="5.10.0" location="./tools/psalm" copy="false"/>
+  <phar name="phpstan" version="1.10.21" installed="1.10.21" location="./tools/phpstan" copy="false"/>
+  <phar name="psalm" version="5.13.0" installed="5.13.0" location="./tools/psalm" copy="false"/>
 </phive>

+ 8 - 8
phpstan-baseline.neon

@@ -101,11 +101,6 @@ parameters:
 			path: src/ORM/Behavior/TreeBehavior.php
 
 		-
-			message: "#^Parameter \\#1 \\$valuePath of method Cake\\\\Collection\\\\Iterator\\\\TreeIterator\\:\\:printer\\(\\) expects \\(callable\\(\\)\\: mixed\\)\\|string, Closure\\|string\\|null given\\.$#"
-			count: 1
-			path: src/ORM/Behavior/TreeBehavior.php
-
-		-
 			message: "#^Unsafe usage of new static\\(\\)\\.$#"
 			count: 2
 			path: src/ORM/EagerLoader.php
@@ -126,14 +121,19 @@ parameters:
 			path: src/Routing/RouteBuilder.php
 
 		-
-			message: "#^Parameter \\#5 \\$trace of class Cake\\\\Error\\\\PhpError constructor expects array, array\\|string given\\.$#"
+			message: "#^Unreachable statement \\- code above always terminates\\.$#"
 			count: 1
 			path: src/TestSuite/TestCase.php
 
 		-
-			message: "#^Unreachable statement \\- code above always terminates\\.$#"
+			message: "#^Offset 0 does not exist on array\\{\\}\\|array\\{0\\: int, 1\\: int, 2\\: int, 3\\: string, mime\\: string, channels\\?\\: int, bits\\?\\: int\\}\\.$#"
 			count: 1
-			path: src/TestSuite/TestCase.php
+			path: src/Validation/Validation.php
+
+		-
+			message: "#^Offset 1 does not exist on array\\{\\}\\|array\\{0\\: int, 1\\: int, 2\\: int, 3\\: string, mime\\: string, channels\\?\\: int, bits\\?\\: int\\}\\.$#"
+			count: 1
+			path: src/Validation/Validation.php
 
 		-
 			message: "#^Unsafe usage of new static\\(\\)\\.$#"

+ 1 - 0
psalm.xml

@@ -48,5 +48,6 @@
         <RedundantPropertyInitializationCheck errorLevel="suppress"/>
         <RedundantCast errorLevel="suppress"/>
         <UndefinedAttributeClass errorLevel="suppress"/>
+        <UnsupportedPropertyReferenceUsage errorLevel="suppress"/>
     </issueHandlers>
 </psalm>

+ 1 - 3
src/Console/ConsoleOptionParser.php

@@ -647,9 +647,7 @@ class ConsoleOptionParser
             return (string)$formatter->xml();
         }
 
-        throw new ConsoleException(
-            sprintf('Invalid format. Output format can be text or xml.')
-        );
+        throw new ConsoleException('Invalid format. Output format can be text or xml.');
     }
 
     /**

+ 1 - 1
src/ORM/Behavior/TreeBehavior.php

@@ -526,7 +526,7 @@ class TreeBehavior extends Behavior
 
                 $nested = $results->listNested();
                 assert($nested instanceof TreeIterator);
-                assert(!is_array($valuePath));
+                assert(is_callable($valuePath) || is_string($valuePath));
 
                 return $nested->printer($valuePath, $keyPath, $spacer);
             }

+ 11 - 5
src/ORM/Locator/LocatorAwareTrait.php

@@ -59,11 +59,17 @@ trait LocatorAwareTrait
      */
     public function getTableLocator(): LocatorInterface
     {
-        /**
-         * @var \Cake\ORM\Locator\LocatorInterface
-         * @psalm-suppress PropertyTypeCoercion
-         */
-        return $this->_tableLocator ??= FactoryLocator::get('Table');
+        if (isset($this->_tableLocator)) {
+            return $this->_tableLocator;
+        }
+
+        $locator = FactoryLocator::get('Table');
+        assert(
+            $locator instanceof LocatorInterface,
+            '`FactoryLocator` must return an instance of Cake\ORM\LocatorInterface for type `Table`.'
+        );
+
+        return $this->_tableLocator = $locator;
     }
 
     /**

+ 1 - 0
src/TestSuite/TestCase.php

@@ -127,6 +127,7 @@ abstract class TestCase extends BaseTestCase
         set_error_handler(
             function (int $code, string $description, string $file, int $line) {
                 $trace = Debugger::trace(['start' => 1, 'format' => 'points']);
+                assert(is_array($trace));
                 $this->_capturedError = new PhpError($code, $description, $file, $line, $trace);
 
                 return true;

+ 2 - 2
tests/TestCase/Mailer/Transport/SmtpTransportTest.php

@@ -387,9 +387,9 @@ class SmtpTransportTest extends TestCase
             ));
         $this->socket->expects($this->exactly(1))
             ->method('write')
-            ->withConsecutive(
+            ->with(...self::withConsecutive(
                 ["EHLO localhost\r\n"],
-            );
+            ));
 
         $this->SmtpTransport->connect();
         $this->assertNull($this->SmtpTransport->getAuthType());