ソースを参照

Merge pull request #15960 from cakephp/4.next-stan

Update Stan tools
ADmad 4 年 前
コミット
122d123856

+ 1 - 1
composer.json

@@ -109,7 +109,7 @@
             "@phpstan",
             "@psalm"
         ],
-        "stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:0.12.94 psalm/phar:~4.9.3 && mv composer.backup composer.json",
+        "stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:0.12.96 psalm/phar:~4.10.0 && mv composer.backup composer.json",
         "test": "phpunit",
         "test-coverage": "phpunit --coverage-clover=clover.xml"
     },

+ 0 - 40
phpstan-baseline.neon

@@ -291,31 +291,6 @@ parameters:
 			path: src/Http/Client/Auth/Digest.php
 
 		-
-			message: "#^Array \\(array\\<non\\-empty\\-string, non\\-empty\\-string\\>\\) does not accept \\(int\\|string\\)\\.$#"
-			count: 1
-			path: src/Http/Client/Request.php
-
-		-
-			message: "#^Array \\(array\\<string, string\\>\\) does not accept key string\\.$#"
-			count: 1
-			path: src/Http/Client/Request.php
-
-		-
-			message: "#^Array \\(array\\<non\\-empty\\-string, non\\-empty\\-string\\>\\) does not accept string\\.$#"
-			count: 1
-			path: src/Http/Client/Response.php
-
-		-
-			message: "#^Array \\(array\\<string, array\\<int, string\\>\\>\\) does not accept key string\\.$#"
-			count: 1
-			path: src/Http/Client/Response.php
-
-		-
-			message: "#^Array \\(array\\<string, string\\>\\) does not accept key string\\.$#"
-			count: 1
-			path: src/Http/Client/Response.php
-
-		-
 			message: "#^Call to an undefined method DateTimeInterface\\:\\:setTimezone\\(\\)\\.$#"
 			count: 1
 			path: src/Http/Cookie/Cookie.php
@@ -331,21 +306,6 @@ parameters:
 			path: src/Http/Cookie/CookieCollection.php
 
 		-
-			message: "#^Array \\(array\\<non\\-empty\\-string, non\\-empty\\-string\\>\\) does not accept string\\.$#"
-			count: 1
-			path: src/Http/Response.php
-
-		-
-			message: "#^Array \\(array\\<string, array\\<int, string\\>\\>\\) does not accept key string\\.$#"
-			count: 1
-			path: src/Http/Response.php
-
-		-
-			message: "#^Array \\(array\\<string, string\\>\\) does not accept key string\\.$#"
-			count: 1
-			path: src/Http/Response.php
-
-		-
 			message: "#^Call to an undefined method DateTimeInterface\\:\\:setTimezone\\(\\)\\.$#"
 			count: 1
 			path: src/Http/Response.php

+ 1 - 0
phpunit.xml.dist

@@ -3,6 +3,7 @@
     colors="true"
     bootstrap="tests/bootstrap.php"
     backupGlobals="true"
+    convertDeprecationsToExceptions="true"
     >
 
     <testsuites>

+ 3 - 3
src/Core/App.php

@@ -126,11 +126,11 @@ class App
             return $class;
         }
 
-        $pluginName = substr($class, 0, $pos);
-        $name = substr($class, $pos + strlen($type));
+        $pluginName = (string)substr($class, 0, $pos);
+        $name = (string)substr($class, $pos + strlen($type));
 
         if ($suffix) {
-            $name = substr($name, 0, -strlen($suffix));
+            $name = (string)substr($name, 0, -strlen($suffix));
         }
 
         $nonPluginNamespaces = [

+ 1 - 1
src/Database/Type/DateType.php

@@ -107,7 +107,7 @@ class DateType extends DateTimeType
         $date = parent::marshal($value);
         if ($date && !$date instanceof I18nDateTimeInterface) {
             // Clear time manually when I18n types aren't available and raw DateTime used
-            /** @psalm-var \DateTime|\DateTimeImmutable $date */
+            /** @var \DateTime|\DateTimeImmutable $date */
             $date->setTime(0, 0, 0);
         }
 

+ 1 - 1
src/Database/Type/ExpressionTypeCasterTrait.php

@@ -49,7 +49,7 @@ trait ExpressionTypeCasterTrait
         $multi = $type !== $baseType;
 
         if ($multi) {
-            /** @psalm-var \Cake\Database\Type\ExpressionTypeInterface $converter */
+            /** @var \Cake\Database\Type\ExpressionTypeInterface $converter */
             return array_map([$converter, 'toExpression'], $value);
         }
 

+ 1 - 1
src/Datasource/QueryTrait.php

@@ -441,7 +441,7 @@ trait QueryTrait
      * ```
      *
      * @param callable|null $formatter The formatting callable.
-     * @param int|true $mode Whether to overwrite, append or prepend the formatter.
+     * @param int|bool $mode Whether to overwrite, append or prepend the formatter.
      * @return $this
      * @throws \InvalidArgumentException
      */

+ 3 - 1
src/Http/Client.php

@@ -619,6 +619,7 @@ class Client implements ClientInterface
      */
     protected function _createRequest(string $method, string $url, $data, $options): Request
     {
+        /** @var array<non-empty-string, non-empty-string> $headers */
         $headers = (array)($options['headers'] ?? []);
         if (isset($options['type'])) {
             $headers = array_merge($headers, $this->_typeHeaders($options['type']));
@@ -647,10 +648,11 @@ class Client implements ClientInterface
      * Returns headers for Accept/Content-Type based on a short type
      * or full mime-type.
      *
+     * @phpstan-param non-empty-string $type
      * @param string $type short type alias or full mimetype.
      * @return array<string, string> Headers to set on the request.
      * @throws \Cake\Core\Exception\CakeException When an unknown type alias is used.
-     * @psalm-return array{Accept: string, Content-Type: string}
+     * @psalm-return array<non-empty-string, non-empty-string>
      */
     protected function _typeHeaders(string $type): array
     {

+ 6 - 2
src/Http/Client/Request.php

@@ -34,6 +34,7 @@ class Request extends Message implements RequestInterface
      *
      * Provides backwards compatible defaults for some properties.
      *
+     * @phpstan-param array<non-empty-string, non-empty-string> $headers
      * @param string $url The request URL
      * @param string $method The HTTP method to use.
      * @param array $headers The HTTP headers to set.
@@ -59,7 +60,8 @@ class Request extends Message implements RequestInterface
     /**
      * Add an array of headers to the request.
      *
-     * @param array $headers The headers to add.
+     * @phpstan-param array<non-empty-string, non-empty-string> $headers
+     * @param array<string, string> $headers The headers to add.
      * @return void
      */
     protected function addHeaders(array $headers): void
@@ -85,7 +87,9 @@ class Request extends Message implements RequestInterface
         if (is_array($content)) {
             $formData = new FormData();
             $formData->addMany($content);
-            $this->addHeaders(['Content-Type' => $formData->contentType()]);
+            /** @phpstan-var array<non-empty-string, non-empty-string> $headers */
+            $headers = ['Content-Type' => $formData->contentType()];
+            $this->addHeaders($headers);
             $content = (string)$formData;
         }
 

+ 1 - 0
src/Http/Client/Response.php

@@ -189,6 +189,7 @@ class Response extends Message implements ResponseInterface
             }
             [$name, $value] = explode(':', $value, 2);
             $value = trim($value);
+            /** @phpstan-var non-empty-string $name */
             $name = trim($name);
 
             $normalized = strtolower($name);

+ 1 - 0
src/Http/Response.php

@@ -542,6 +542,7 @@ class Response implements ResponseInterface
     /**
      * Sets a header.
      *
+     * @phpstan-param non-empty-string $header
      * @param string $header Header key.
      * @param string $value Header value.
      * @return void

+ 1 - 0
src/Mailer/Email.php

@@ -605,6 +605,7 @@ class Email implements JsonSerializable, Serializable
             }
         });
 
+        /** @psalm-var array */
         return $array;
     }
 

+ 1 - 0
src/Mailer/Message.php

@@ -1914,6 +1914,7 @@ class Message implements JsonSerializable, Serializable
             }
         });
 
+        /** @psalm-var array */
         return $array;
     }
 

+ 1 - 1
src/TestSuite/Fixture/FixtureManager.php

@@ -66,7 +66,7 @@ class FixtureManager
     /**
      * List of TestCase class name that have been processed
      *
-     * @var array
+     * @var array<string, bool>
      */
     protected $_processed = [];