Browse Source

Fix failing tests and linting

- newer phpunit eats our deprecation warnings.
- Fix phpcs error and phpstan config warning
- Fix new type issues that phpstan found
- Update split repos phpstan config
Mark Story 1 year ago
parent
commit
f25c70685a

+ 7 - 4
phpstan.neon.dist

@@ -2,18 +2,21 @@ includes:
 	- phpstan-baseline.neon
 
 rules:
-    - Symplify\PHPStanRules\Rules\Explicit\NoMixedPropertyFetcherRule
-    - Symplify\PHPStanRules\Rules\Explicit\NoMixedMethodCallerRule
+	- Symplify\PHPStanRules\Rules\Explicit\NoMixedPropertyFetcherRule
+	- Symplify\PHPStanRules\Rules\Explicit\NoMixedMethodCallerRule
 
 parameters:
 	level: 8
-	checkMissingIterableValueType: false
-	checkGenericClassInNonGenericObjectType: false
 	treatPhpDocTypesAsCertain: false
 	bootstrapFiles:
 		- tests/bootstrap.php
 	paths:
 		- src/
+	ignoreErrors:
+		-
+		  identifier: missingType.iterableValue
+		-
+		  identifier: missingType.generics
 
 services:
 	-

+ 4 - 2
src/Database/phpstan.neon.dist

@@ -1,7 +1,5 @@
 parameters:
 	level: 8
-	checkMissingIterableValueType: false
-	checkGenericClassInNonGenericObjectType: false
 	treatPhpDocTypesAsCertain: false
 	bootstrapFiles:
 		- tests/phpstan-bootstrap.php
@@ -10,4 +8,8 @@ parameters:
 	excludePaths:
 		- vendor/
 	ignoreErrors:
+		-
+			identifier: missingType.iterableValue
+		-
+			identifier: missingType.generics
 		- '#Unsafe usage of new static\(\).#'

+ 4 - 2
src/Datasource/phpstan.neon.dist

@@ -1,7 +1,5 @@
 parameters:
 	level: 8
-	checkMissingIterableValueType: false
-	checkGenericClassInNonGenericObjectType: false
 	treatPhpDocTypesAsCertain: false
 	bootstrapFiles:
 		- tests/phpstan-bootstrap.php
@@ -10,6 +8,10 @@ parameters:
 	excludePaths:
 		- vendor/
 	ignoreErrors:
+		-
+			identifier: missingType.iterableValue
+		-
+			identifier: missingType.generics
 		- "#^Template type T of method Cake\\\\Datasource\\\\QueryInterface\\:\\:all\\(\\) is not referenced in a parameter\\.$#"
 		- '#Class Cake\\Database\\Driver\\.+ not found.#'
 		- '#Class Cake\\Database\\Connection not found.#'

+ 3 - 2
src/Event/EventManager.php

@@ -109,13 +109,13 @@ class EventManager implements EventManagerInterface
             return $this;
         }
 
-        if (!$callable && !is_callable($options)) {
+        if ($callable === null && !is_callable($options)) {
             throw new InvalidArgumentException(
                 'Second argument of `EventManager::on()` must be a callable if `$callable` is null.'
             );
         }
 
-        if (!$callable) {
+        if ($callable === null) {
             /** @var callable $options */
             $this->_listeners[$eventKey][static::$defaultPriority][] = [
                 'callable' => $options(...),
@@ -124,6 +124,7 @@ class EventManager implements EventManagerInterface
             return $this;
         }
 
+        /** @var array $options */
         $priority = $options['priority'] ?? static::$defaultPriority;
         $this->_listeners[$eventKey][$priority][] = [
             'callable' => $callable(...),

+ 3 - 2
src/Http/Client/FormData.php

@@ -157,8 +157,9 @@ class FormData implements Countable, Stringable
             if (stream_is_local($value)) {
                 $finfo = new finfo(FILEINFO_MIME);
                 $metadata = stream_get_meta_data($value);
-                $contentType = (string)$finfo->file($metadata['uri']);
-                $filename = basename($metadata['uri']);
+                $uri = $metadata['uri'] ?? '';
+                $contentType = (string)$finfo->file($uri);
+                $filename = basename($uri);
             }
         } else {
             $finfo = new finfo(FILEINFO_MIME);

+ 4 - 2
src/Http/phpstan.neon.dist

@@ -1,7 +1,5 @@
 parameters:
 	level: 8
-	checkMissingIterableValueType: false
-	checkGenericClassInNonGenericObjectType: false
 	treatPhpDocTypesAsCertain: false
 	bootstrapFiles:
 		- tests/phpstan-bootstrap.php
@@ -13,6 +11,10 @@ parameters:
 	    - Session.php
 	    - vendor/
 	ignoreErrors:
+		-
+			identifier: missingType.iterableValue
+		-
+			identifier: missingType.generics
 		- '#Unsafe usage of new static\(\).#'
 		- "#^Constructor of class Cake\\\\Http\\\\Client\\\\Auth\\\\Digest has an unused parameter \\$options\\.$#"
 		- '#Call to static method getRequest\(\) on an unknown class Cake\\Routing\\Router.#'

+ 1 - 1
src/ORM/Query/SelectQuery.php

@@ -1580,7 +1580,7 @@ class SelectQuery extends DbSelectQuery implements JsonSerializable, QueryInterf
     protected function _execute(): iterable
     {
         $this->triggerBeforeFind();
-        if ($this->_results) {
+        if ($this->_results !== null) {
             return $this->_results;
         }
 

+ 7 - 2
src/ORM/phpstan.neon.dist

@@ -1,7 +1,5 @@
 parameters:
 	level: 8
-	checkMissingIterableValueType: false
-	checkGenericClassInNonGenericObjectType: false
 	treatPhpDocTypesAsCertain: false
 	bootstrapFiles:
 		- tests/phpstan-bootstrap.php
@@ -10,7 +8,14 @@ parameters:
 	excludePaths:
 		- vendor/
 	ignoreErrors:
+		-
+			identifier: missingType.iterableValue
+		-
+			identifier: missingType.generics
+
 		- '#Unsafe usage of new static\(\).#'
 		- "#^Method Cake\\\\ORM\\\\Behavior\\\\TreeBehavior\\:\\:_scope\\(\\) should return T of Cake\\\\ORM\\\\Query\\\\DeleteQuery\\|Cake\\\\ORM\\\\Query\\\\SelectQuery\\|Cake\\\\ORM\\\\Query\\\\UpdateQuery but returns Cake\\\\ORM\\\\Query\\\\DeleteQuery\\|Cake\\\\ORM\\\\Query\\\\SelectQuery\\|Cake\\\\ORM\\\\Query\\\\UpdateQuery\\.$#"
 		- "#^PHPDoc tag @return with type Cake\\\\ORM\\\\Query\\\\SelectQuery\\<TSubject of array\\|Cake\\\\Datasource\\\\EntityInterface\\> is not subtype of native type static\\(Cake\\\\ORM\\\\Query\\\\SelectQuery\\<TSubject of array\\|Cake\\\\Datasource\\\\EntityInterface\\>\\)\\.$#"
 		- "#^Method Cake\\\\ORM\\\\Query\\\\SelectQuery\\:\\:find\\(\\) should return static\\(Cake\\\\ORM\\\\Query\\\\SelectQuery\\<TSubject of array\\|Cake\\\\Datasource\\\\EntityInterface\\>\\) but returns Cake\\\\ORM\\\\Query\\\\SelectQuery\\<TSubject of array\\|Cake\\\\Datasource\\\\EntityInterface\\>\\.$#"
+		- "#^Access to an undefined property Cake\\\\ORM\\\\Query\\\\SelectQuery\\<TSubject of array\\|Cake\\\\Datasource\\\\EntityInterface\\>\\:\\:\\$bufferedResults\\.$#"
+		- "#^Parameter \\#2 \\$results of method Cake\\\\ORM\\\\EagerLoader\\:\\:loadExternal\\(\\) expects iterable, Cake\\\\Database\\\\StatementInterface\\|iterable given\\.$#"

+ 3 - 2
src/Validation/phpstan.neon.dist

@@ -1,7 +1,5 @@
 parameters:
 	level: 8
-	checkMissingIterableValueType: false
-	checkGenericClassInNonGenericObjectType: false
 	treatPhpDocTypesAsCertain: false
 	bootstrapFiles:
 		- tests/phpstan-bootstrap.php
@@ -9,3 +7,6 @@ parameters:
 		- ./
 	excludePaths:
 	    - vendor/
+	ignoreErrors:
+		-
+			identifier: missingType.iterableValue

+ 1 - 0
src/View/Widget/SelectBoxWidget.php

@@ -253,6 +253,7 @@ class SelectBoxWidget extends BasicWidget
         foreach ($options as $key => $val) {
             // Option groups
             $isIterable = is_iterable($val);
+            /** @var \ArrayAccess|array $val */
             if (
                 (
                     !is_int($key) &&

+ 3 - 2
tests/TestCase/Command/Helper/TableHelperTest.php

@@ -20,6 +20,7 @@ use Cake\Command\Helper\TableHelper;
 use Cake\Console\ConsoleIo;
 use Cake\Console\TestSuite\StubConsoleOutput;
 use Cake\TestSuite\TestCase;
+use UnexpectedValueException;
 
 /**
  * TableHelper test.
@@ -386,7 +387,7 @@ class TableHelperTest extends TestCase
      */
     public function testTextRightsideTheTextRightTag(): void
     {
-        $this->expectException(\UnexpectedValueException::class);
+        $this->expectException(UnexpectedValueException::class);
         $data = [
             ['Item', 'Price per piece (yen)'],
             ['Apple', '<text-right>some</text-right>text'],
@@ -399,7 +400,7 @@ class TableHelperTest extends TestCase
      */
     public function testTextLeftsideTheTextRightTag(): void
     {
-        $this->expectException(\UnexpectedValueException::class);
+        $this->expectException(UnexpectedValueException::class);
         $data = [
             ['Item', 'Price per piece (yen)'],
             ['Apple', 'text<text-right>some</text-right>'],

+ 3 - 5
tests/TestCase/ORM/TableTest.php

@@ -1295,11 +1295,9 @@ class TableTest extends TestCase
         $this->assertNotEmpty($article);
 
         // Options arrays are deprecated but should work
-        $this->deprecated(function () use ($articles) {
-            $article = $articles->find('titled', ['title' => 'Second Article'])->first();
-            $this->assertNotEmpty($article);
-            $this->assertEquals('Second Article', $article->title);
-        });
+        $article = $articles->find('titled', ['title' => 'Second Article'])->first();
+        $this->assertNotEmpty($article);
+        $this->assertEquals('Second Article', $article->title);
 
         // Named parameters should be compatible with options finders
         $article = $articles->find('titled', title: 'Second Article')->first();