Browse Source

5.x phpstan updates (#16998)

5.x PHPStan updates
Mark Scherer 3 years ago
parent
commit
d594e4d35a

+ 1 - 1
.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.9.12" installed="1.9.12" location="./tools/phpstan" copy="false"/>
+  <phar name="phpstan" version="1.9.16" installed="1.9.16" location="./tools/phpstan" copy="false"/>
   <phar name="psalm" version="5.6.0" installed="5.6.0" location="./tools/psalm" copy="false"/>
 </phive>

+ 30 - 0
phpstan-baseline.neon

@@ -1,6 +1,11 @@
 parameters:
 	ignoreErrors:
 		-
+			message: "#^Parameter \\#1 \\$iterator of class LimitIterator constructor expects TIterator of Iterator\\<mixed, mixed\\>, \\$this\\(Cake\\\\Collection\\\\Collection\\) given\\.$#"
+			count: 3
+			path: src/Collection/Collection.php
+
+		-
 			message: "#^Unsafe usage of new static\\(\\)\\.$#"
 			count: 1
 			path: src/Collection/Iterator/NestIterator.php
@@ -11,6 +16,21 @@ parameters:
 			path: src/Collection/Iterator/NoChildrenIterator.php
 
 		-
+			message: "#^Parameter \\#1 \\$iterator of class LimitIterator constructor expects TIterator of Iterator\\<mixed, mixed\\>, \\$this\\(Cake\\\\Collection\\\\Iterator\\\\TreeIterator\\) given\\.$#"
+			count: 3
+			path: src/Collection/Iterator/TreeIterator.php
+
+		-
+			message: "#^Parameter \\#1 \\$iterator of class LimitIterator constructor expects TIterator of Iterator\\<mixed, mixed\\>, \\$this\\(Cake\\\\Collection\\\\Iterator\\\\TreePrinter\\) given\\.$#"
+			count: 3
+			path: src/Collection/Iterator/TreePrinter.php
+
+		-
+			message: "#^Parameter \\#1 \\$iterator of class LimitIterator constructor expects TIterator of Iterator\\<mixed, mixed\\>, \\$this\\(Cake\\\\Collection\\\\Iterator\\\\ZipIterator\\) given\\.$#"
+			count: 3
+			path: src/Collection/Iterator/ZipIterator.php
+
+		-
 			message: "#^Unsafe usage of new static\\(\\)\\.$#"
 			count: 2
 			path: src/Console/ConsoleOptionParser.php
@@ -76,6 +96,11 @@ parameters:
 			path: src/Http/Session.php
 
 		-
+			message: "#^Call to an undefined method Cake\\\\I18n\\\\Date\\:\\:getTimestamp\\(\\)\\.$#"
+			count: 1
+			path: src/I18n/Date.php
+
+		-
 			message: "#^Call to an undefined method Cake\\\\I18n\\\\Date\\|Cake\\\\I18n\\\\DateTime\\:\\:setTimezone\\(\\)\\.$#"
 			count: 1
 			path: src/I18n/RelativeTimeFormatter.php
@@ -101,6 +126,11 @@ parameters:
 			path: src/ORM/Query/SelectQuery.php
 
 		-
+			message: "#^Parameter \\#1 \\$iterator of class LimitIterator constructor expects TIterator of Iterator\\<mixed, mixed\\>, \\$this\\(Cake\\\\ORM\\\\ResultSet\\<T of array\\|Cake\\\\Datasource\\\\EntityInterface\\>\\) given\\.$#"
+			count: 2
+			path: src/ORM/ResultSet.php
+
+		-
 			message: "#^Unsafe usage of new static\\(\\)\\.$#"
 			count: 1
 			path: src/Routing/RouteBuilder.php

+ 2 - 2
tests/TestCase/ORM/Association/HasOneTest.php

@@ -284,7 +284,7 @@ class HasOneTest extends TestCase
         $query = $this->user->find();
 
         $this->listenerCalled = false;
-        $this->profile->getEventManager()->on('Model.beforeFind', function ($event, $query, $options, $primary): void {
+        $this->profile->getEventManager()->on('Model.beforeFind', function ($event, $query, $options, bool $primary): void {
             $this->listenerCalled = true;
             $this->assertInstanceOf('Cake\Event\Event', $event);
             $this->assertInstanceOf('Cake\ORM\Query', $query);
@@ -310,7 +310,7 @@ class HasOneTest extends TestCase
         $opts = new ArrayObject(['something' => 'more']);
         $this->profile->getEventManager()->on(
             'Model.beforeFind',
-            function ($event, $query, $options, $primary) use ($opts): void {
+            function ($event, $query, $options, bool $primary) use ($opts): void {
                 $this->listenerCalled = true;
                 $this->assertInstanceOf('Cake\Event\Event', $event);
                 $this->assertInstanceOf('Cake\ORM\Query', $query);

+ 4 - 4
tests/TestCase/ORM/Query/SelectQueryTest.php

@@ -2625,12 +2625,12 @@ class SelectQueryTest extends TestCase
         ]);
         $this->assertFalse($query->isEagerLoaded());
 
-        $table->getEventManager()->on('Model.beforeFind', function ($e, $q, $o, $primary): void {
+        $table->getEventManager()->on('Model.beforeFind', function ($e, $q, $o, bool $primary): void {
             $this->assertTrue($primary);
         });
 
         $this->getTableLocator()->get('articles')
-            ->getEventManager()->on('Model.beforeFind', function ($e, $q, $o, $primary): void {
+            ->getEventManager()->on('Model.beforeFind', function ($e, $q, $o, bool $primary): void {
                 $this->assertFalse($primary);
             });
         $query->all();
@@ -2653,12 +2653,12 @@ class SelectQueryTest extends TestCase
         ]);
         $this->assertFalse($query->isEagerLoaded());
 
-        $table->getEventManager()->on('Model.beforeFind', function ($e, $q, $o, $primary): void {
+        $table->getEventManager()->on('Model.beforeFind', function ($e, $q, $o, bool $primary): void {
             $this->assertTrue($primary);
         });
 
         $this->getTableLocator()->get('articles')
-            ->getEventManager()->on('Model.beforeFind', function ($e, $q, $o, $primary): void {
+            ->getEventManager()->on('Model.beforeFind', function ($e, $q, $o, bool $primary): void {
                 $this->assertFalse($primary);
             });
         $query->all();

+ 2 - 2
tests/TestCase/ORM/TableTest.php

@@ -5982,7 +5982,7 @@ class TableTest extends TestCase
         $associationBeforeFindCount = 0;
         $table->getAssociation('authors')->getTarget()->getEventManager()->on(
             'Model.beforeFind',
-            function (EventInterface $event, SelectQuery $query, ArrayObject $options, $primary) use (&$associationBeforeFindCount): void {
+            function (EventInterface $event, SelectQuery $query, ArrayObject $options, bool $primary) use (&$associationBeforeFindCount): void {
                 $this->assertIsBool($primary);
                 $associationBeforeFindCount++;
             }
@@ -5991,7 +5991,7 @@ class TableTest extends TestCase
         $beforeFindCount = 0;
         $eventManager->on(
             'Model.beforeFind',
-            function (EventInterface $event, SelectQuery $query, ArrayObject $options, $primary) use (&$beforeFindCount): void {
+            function (EventInterface $event, SelectQuery $query, ArrayObject $options, bool $primary) use (&$beforeFindCount): void {
                 $this->assertIsBool($primary);
                 $beforeFindCount++;
             }

+ 1 - 1
tests/TestCase/View/Helper/FormHelperTest.php

@@ -130,7 +130,7 @@ class FormHelperTest extends TestCase
     public function tearDown(): void
     {
         parent::tearDown();
-        unset($this->Form, $this->Controller, $this->View);
+        unset($this->Form, $this->View);
     }
 
     /**