Browse Source

Fix phpstan errors from newer phpstan

Backport fixes from 5.next
Mark Story 1 year ago
parent
commit
f72707c266

+ 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
@@ -11,3 +9,7 @@ parameters:
 		- vendor/
 	ignoreErrors:
 		- '#Unsafe usage of new static\(\).#'
+		-
+			identifier: missingType.iterableValue
+		-
+			identifier: missingType.generics

+ 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);

+ 8 - 6
src/Http/phpstan.neon.dist

@@ -1,17 +1,19 @@
 parameters:
 	level: 8
-	checkMissingIterableValueType: false
-	checkGenericClassInNonGenericObjectType: false
 	treatPhpDocTypesAsCertain: false
 	bootstrapFiles:
 		- tests/phpstan-bootstrap.php
 	paths:
 		- ./
 	excludePaths:
-	    - BaseApplication.php
-	    - Runner.php
-	    - Session.php
-	    - vendor/
+		- BaseApplication.php
+		- Runner.php
+		- 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\\.$#"

+ 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;
         }
 

+ 4 - 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,6 +8,10 @@ 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\\>\\)\\.$#"

+ 5 - 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,8 @@ parameters:
 		- ./
 	excludePaths:
 	    - vendor/
+	ignoreErrors:
+		-
+			identifier: missingType.iterableValue
+		-
+			identifier: missingType.generics

+ 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) &&