Browse Source

chore: more types (#7598)

Dariusz Rumiński 1 year ago
parent
commit
2732da24a5

+ 1 - 1
dev-tools/phpstan/baseline.php

@@ -422,7 +422,7 @@ $ignoreErrors[] = [
 	'path' => __DIR__ . '/../../src/Tokenizer/Tokens.php',
 ];
 $ignoreErrors[] = [
-	'message' => '#^Parameter \\#1 \\$array \\(array\\<PhpCsFixer\\\\Tokenizer\\\\Token\\>\\) of method PhpCsFixer\\\\Tokenizer\\\\Tokens\\:\\:fromArray\\(\\) should be contravariant with parameter \\$array \\(array\\<int, mixed\\>\\) of method SplFixedArray\\<PhpCsFixer\\\\Tokenizer\\\\Token\\>\\:\\:fromArray\\(\\)$#',
+	'message' => '#^Parameter \\#1 \\$array \\(array\\<int, PhpCsFixer\\\\Tokenizer\\\\Token\\>\\) of method PhpCsFixer\\\\Tokenizer\\\\Tokens\\:\\:fromArray\\(\\) should be contravariant with parameter \\$array \\(array\\<int, mixed\\>\\) of method SplFixedArray\\<PhpCsFixer\\\\Tokenizer\\\\Token\\>\\:\\:fromArray\\(\\)$#',
 	'count' => 1,
 	'path' => __DIR__ . '/../../src/Tokenizer/Tokens.php',
 ];

+ 1 - 1
src/AbstractFunctionReferenceFixer.php

@@ -43,7 +43,7 @@ abstract class AbstractFunctionReferenceFixer extends AbstractFixer
      * Looks up Tokens sequence for suitable candidates and delivers boundaries information,
      * which can be supplied by other methods in this abstract class.
      *
-     * @return null|int[] returns $functionName, $openParenthesis, $closeParenthesis packed into array
+     * @return ?array{int, int, int} returns $functionName, $openParenthesis, $closeParenthesis packed into array
      */
     protected function find(string $functionNameToSearch, Tokens $tokens, int $start = 0, ?int $end = null): ?array
     {

+ 2 - 2
src/AbstractPhpdocToTypeDeclarationFixer.php

@@ -103,7 +103,7 @@ abstract class AbstractPhpdocToTypeDeclarationFixer extends AbstractFixer implem
     }
 
     /**
-     * @return Annotation[]
+     * @return list<Annotation>
      */
     protected function getAnnotationsFromDocComment(string $name, Tokens $tokens, int $docCommentIndex): array
     {
@@ -123,7 +123,7 @@ abstract class AbstractPhpdocToTypeDeclarationFixer extends AbstractFixer implem
     }
 
     /**
-     * @return Token[]
+     * @return list<Token>
      */
     protected function createTypeDeclarationTokens(string $type, bool $isNullable): array
     {

+ 7 - 8
src/AbstractPhpdocTypesFixer.php

@@ -31,7 +31,7 @@ abstract class AbstractPhpdocTypesFixer extends AbstractFixer
     /**
      * The annotation tags search inside.
      *
-     * @var string[]
+     * @var list<string>
      */
     protected array $tags;
 
@@ -93,17 +93,16 @@ abstract class AbstractPhpdocTypesFixer extends AbstractFixer
     }
 
     /**
-     * @param string[] $types
+     * @param list<string> $types
      *
-     * @return string[]
+     * @return list<string>
      */
     private function normalizeTypes(array $types): array
     {
-        foreach ($types as $index => $type) {
-            $types[$index] = $this->normalizeType($type);
-        }
-
-        return $types;
+        return array_map(
+            fn (string $type): string => $this->normalizeType($type),
+            $types
+        );
     }
 
     /**

+ 1 - 1
src/Cache/Cache.php

@@ -75,7 +75,7 @@ final class Cache implements CacheInterface
             'hashes' => $this->hashes,
         ]);
 
-        if (JSON_ERROR_NONE !== json_last_error()) {
+        if (JSON_ERROR_NONE !== json_last_error() || false === $json) {
             throw new \UnexpectedValueException(sprintf(
                 'Cannot encode cache signature to JSON, error: "%s". If you have non-UTF8 chars in your signature, like in license for `header_comment`, consider enabling `ext-mbstring` or install `symfony/polyfill-mbstring`.',
                 json_last_error_msg()

+ 2 - 2
src/Console/Command/DescribeCommand.php

@@ -56,7 +56,7 @@ final class DescribeCommand extends Command
     protected static $defaultName = 'describe';
 
     /**
-     * @var string[]
+     * @var ?list<string>
      */
     private $setNames;
 
@@ -400,7 +400,7 @@ final class DescribeCommand extends Command
     }
 
     /**
-     * @return string[]
+     * @return list<string>
      */
     private function getSetNames(): array
     {

+ 1 - 1
src/Console/ConfigurationResolver.php

@@ -531,7 +531,7 @@ final class ConfigurationResolver
     /**
      * Compute file candidates for config file.
      *
-     * @return string[]
+     * @return list<string>
      */
     private function computeConfigFiles(): array
     {

+ 1 - 1
src/Console/WarningsDetector.php

@@ -60,7 +60,7 @@ final class WarningsDetector
     }
 
     /**
-     * @return string[]
+     * @return list<string>
      */
     public function getWarnings(): array
     {

+ 6 - 6
src/DocBlock/Annotation.php

@@ -29,7 +29,7 @@ final class Annotation
     /**
      * All the annotation tag names with types.
      *
-     * @var string[]
+     * @var list<string>
      */
     private static array $tags = [
         'method',
@@ -81,7 +81,7 @@ final class Annotation
     /**
      * The cached types.
      *
-     * @var null|string[]
+     * @var null|list<string>
      */
     private $types;
 
@@ -125,7 +125,7 @@ final class Annotation
     /**
      * Get all the annotation tag names with types.
      *
-     * @return string[]
+     * @return list<string>
      */
     public static function getTagsWithTypes(): array
     {
@@ -192,7 +192,7 @@ final class Annotation
     /**
      * Get the types associated with this annotation.
      *
-     * @return string[]
+     * @return list<string>
      */
     public function getTypes(): array
     {
@@ -209,7 +209,7 @@ final class Annotation
     /**
      * Set the types associated with this annotation.
      *
-     * @param string[] $types
+     * @param list<string> $types
      */
     public function setTypes(array $types): void
     {
@@ -223,7 +223,7 @@ final class Annotation
     /**
      * Get the normalized types associated with this annotation, so they can easily be compared.
      *
-     * @return string[]
+     * @return list<string>
      */
     public function getNormalizedTypes(): array
     {

+ 1 - 1
src/DocBlock/TypeExpression.php

@@ -210,7 +210,7 @@ final class TypeExpression
     }
 
     /**
-     * @return string[]
+     * @return list<string>
      */
     public function getTypes(): array
     {

Some files were not shown because too many files changed in this diff