From 51d7431dbe802827bac61907d7bcb58a168dff81 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes <ondrej@mirtes.cz> Date: Tue, 12 Oct 2021 16:11:25 +0200 Subject: [PATCH] Unify array shape description with PHPDoc type syntax --- phpstan-baseline.neon | 2 +- src/Type/Constant/ConstantArrayType.php | 13 +- .../Analyser/LegacyNodeScopeResolverTest.php | 258 +++++++++--------- tests/PHPStan/Analyser/ScopeTest.php | 4 +- tests/PHPStan/Analyser/TypeSpecifierTest.php | 8 +- .../data/array-shapes-keys-strings.php | 4 +- .../Analyser/data/array_map_multiple.php | 10 +- .../Analyser/data/arrow-function-types.php | 14 +- .../Analyser/data/assign-nested-arrays.php | 4 +- tests/PHPStan/Analyser/data/bug-1283.php | 2 +- tests/PHPStan/Analyser/data/bug-1861.php | 2 +- tests/PHPStan/Analyser/data/bug-1924.php | 2 +- tests/PHPStan/Analyser/data/bug-2001.php | 14 +- tests/PHPStan/Analyser/data/bug-2232.php | 2 +- tests/PHPStan/Analyser/data/bug-2378.php | 4 +- tests/PHPStan/Analyser/data/bug-2677.php | 2 +- tests/PHPStan/Analyser/data/bug-2733.php | 2 +- tests/PHPStan/Analyser/data/bug-3009.php | 8 +- tests/PHPStan/Analyser/data/bug-3269.php | 4 +- tests/PHPStan/Analyser/data/bug-3276.php | 4 +- tests/PHPStan/Analyser/data/bug-3351.php | 2 +- tests/PHPStan/Analyser/data/bug-3558.php | 4 +- tests/PHPStan/Analyser/data/bug-3991.php | 2 +- tests/PHPStan/Analyser/data/bug-4099.php | 12 +- tests/PHPStan/Analyser/data/bug-4213.php | 2 +- tests/PHPStan/Analyser/data/bug-4504.php | 2 +- tests/PHPStan/Analyser/data/bug-4558.php | 2 +- tests/PHPStan/Analyser/data/bug-4587.php | 10 +- tests/PHPStan/Analyser/data/bug-4606.php | 4 +- tests/PHPStan/Analyser/data/bug-4650.php | 4 +- tests/PHPStan/Analyser/data/bug-4700.php | 8 +- tests/PHPStan/Analyser/data/bug-4814.php | 2 +- tests/PHPStan/Analyser/data/bug-5017.php | 2 +- tests/PHPStan/Analyser/data/bug-5219.php | 2 +- tests/PHPStan/Analyser/data/bug-5584.php | 2 +- .../PHPStan/Analyser/data/bug-empty-array.php | 8 +- tests/PHPStan/Analyser/data/bug-pr-339.php | 8 +- .../Analyser/data/closure-return-type.php | 2 +- tests/PHPStan/Analyser/data/closure-types.php | 14 +- tests/PHPStan/Analyser/data/compact.php | 8 +- .../data/conditional-non-empty-array.php | 2 +- .../Analyser/data/empty-array-shape.php | 2 +- tests/PHPStan/Analyser/data/generics.php | 18 +- tests/PHPStan/Analyser/data/minmax-arrays.php | 10 +- ...missing-closure-native-return-typehint.php | 2 +- tests/PHPStan/Analyser/data/native-types.php | 4 +- tests/PHPStan/Analyser/data/preg_split.php | 4 +- .../PHPStan/Analyser/data/proc_get_status.php | 2 +- tests/PHPStan/Analyser/data/type-aliases.php | 2 +- tests/PHPStan/Levels/data/acceptTypes-5.json | 14 +- tests/PHPStan/Levels/data/acceptTypes-7.json | 8 +- .../Levels/data/arrayDestructuring-3.json | 2 +- .../Levels/data/arrayDimFetches-3.json | 4 +- .../Levels/data/arrayDimFetches-7.json | 8 +- .../PHPStan/Levels/data/stubs-methods-4.json | 14 +- tests/PHPStan/PhpDoc/TypeDescriptionTest.php | 33 +++ .../Arrays/AppendedArrayItemTypeRuleTest.php | 6 +- .../Arrays/ArrayDestructuringRuleTest.php | 6 +- ...nexistentOffsetInArrayDimFetchRuleTest.php | 24 +- .../Arrays/OffsetAccessAssignmentRuleTest.php | 4 +- tests/PHPStan/Rules/Cast/EchoRuleTest.php | 6 +- tests/PHPStan/Rules/Cast/PrintRuleTest.php | 6 +- ...mpossibleCheckTypeFunctionCallRuleTest.php | 32 +-- ...rictComparisonOfDifferentTypesRuleTest.php | 8 +- .../Rules/Functions/CallCallablesRuleTest.php | 12 +- .../Functions/ClosureReturnTypeRuleTest.php | 2 +- .../Generators/YieldFromTypeRuleTest.php | 2 +- .../Rules/Generators/YieldTypeRuleTest.php | 2 +- .../Rules/Methods/CallMethodsRuleTest.php | 20 +- .../Methods/CallStaticMethodsRuleTest.php | 2 +- .../Rules/Methods/ReturnTypeRuleTest.php | 6 +- .../InvalidUnaryOperationRuleTest.php | 2 +- .../PHPStan/Rules/Variables/EmptyRuleTest.php | 12 +- .../PHPStan/Rules/Variables/IssetRuleTest.php | 24 +- .../Rules/Variables/NullCoalesceRuleTest.php | 20 +- tests/PHPStan/Type/TypeCombinatorTest.php | 44 +-- tests/PHPStan/Type/UnionTypeTest.php | 10 +- tests/e2e/ResultCacheEndToEndTest.php | 2 +- 78 files changed, 443 insertions(+), 401 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 8078e4d048..f04295337a 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -235,7 +235,7 @@ parameters: path: src/Rules/Api/ApiTraitUseRule.php - - message: "#^Binary operation \"\\+\" between array\\(class\\-string\\<TNodeType of PhpParser\\\\Node\\>\\) and array\\<string, class\\-string\\>\\|false results in an error\\.$#" + message: "#^Binary operation \"\\+\" between array{class\\-string\\<TNodeType of PhpParser\\\\Node\\>} and array\\<string, class\\-string\\>\\|false results in an error\\.$#" count: 1 path: src/Rules/Registry.php diff --git a/src/Type/Constant/ConstantArrayType.php b/src/Type/Constant/ConstantArrayType.php index 7a800fc291..cf4d7daa57 100644 --- a/src/Type/Constant/ConstantArrayType.php +++ b/src/Type/Constant/ConstantArrayType.php @@ -728,7 +728,16 @@ public function describe(VerbosityLevel $level): string $exportValuesOnly = false; } - $items[] = sprintf('%s%s => %s', $isOptional ? '?' : '', var_export($keyType->getValue(), true), $valueType->describe($level)); + $keyDescription = $keyType->getValue(); + if (is_string($keyDescription)) { + if (strpos($keyDescription, '"') !== false) { + $keyDescription = sprintf('\'%s\'', $keyDescription); + } elseif (strpos($keyDescription, '\'') !== false) { + $keyDescription = sprintf('"%s"', $keyDescription); + } + } + + $items[] = sprintf('%s%s: %s', $keyDescription, $isOptional ? '?' : '', $valueType->describe($level)); $values[] = $valueType->describe($level); } @@ -740,7 +749,7 @@ public function describe(VerbosityLevel $level): string } return sprintf( - 'array(%s%s)', + 'array{%s%s}', implode(', ', $exportValuesOnly ? $values : $items), $append ); diff --git a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php index 44d3ccba52..d72df9742b 100644 --- a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php @@ -165,7 +165,7 @@ public function dataUnionAndIntersection(): array 'self::IPSUM_CONSTANT', ], [ - 'array(1, 2, 3)', + 'array{1, 2, 3}', 'parent::PARENT_CONSTANT', ], [ @@ -252,19 +252,19 @@ public function dataAssignInIf(): array $testScope, 'arrOne', TrinaryLogic::createYes(), - 'array(\'one\')', + 'array{\'one\'}', ], [ $testScope, 'arrTwo', TrinaryLogic::createYes(), - 'array(\'test\' => \'two\', 0 => Foo)', + 'array{test: \'two\', 0: Foo}', ], [ $testScope, 'arrThree', TrinaryLogic::createYes(), - 'array(\'three\')', + 'array{\'three\'}', ], [ $testScope, @@ -300,7 +300,7 @@ public function dataAssignInIf(): array $testScope, 'anotherArray', TrinaryLogic::createYes(), - 'array(\'test\' => array(\'another\'))', + 'array{test: array{\'another\'}}', ], [ $testScope, @@ -485,13 +485,13 @@ public function dataAssignInIf(): array $testScope, 'nullableIntegers', TrinaryLogic::createYes(), - 'array(1, 2, 3, null)', + 'array{1, 2, 3, null}', ], [ $testScope, 'union', TrinaryLogic::createYes(), - 'array(1, 2, 3, \'foo\')', + 'array{1, 2, 3, \'foo\'}', '1|2|3|\'foo\'', ], [ @@ -659,7 +659,7 @@ public function dataAssignInIf(): array $testScope, 'arrayOfIntegers', TrinaryLogic::createYes(), - 'array(1, 2, 3)', + 'array{1, 2, 3}', ], [ $testScope, @@ -783,7 +783,7 @@ public function dataConstantTypes(): array [ $testScope, 'literalArray', - 'array(\'a\' => 2, \'b\' => 4, \'c\' => 2, \'d\' => 4)', + 'array{a: 2, b: 4, c: 2, d: 4}', ], [ $testScope, @@ -823,7 +823,7 @@ public function dataConstantTypes(): array [ $testScope, 'arrayOverwrittenInForLoop', - 'array(\'a\' => int, \'b\' => \'bar\'|\'foo\')', + 'array{a: int, b: \'bar\'|\'foo\'}', ], [ $testScope, @@ -1560,31 +1560,31 @@ public function dataCasts(): array '(float) $str', ], [ - 'array(\'\' . "\0" . \'TypesNamespaceCasts\\\\Foo\' . "\0" . \'foo\' => TypesNamespaceCasts\Foo, \'\' . "\0" . \'TypesNamespaceCasts\\\\Foo\' . "\0" . \'int\' => int, \'\' . "\0" . \'*\' . "\0" . \'protectedInt\' => int, \'publicInt\' => int, \'\' . "\0" . \'TypesNamespaceCasts\\\\Bar\' . "\0" . \'barProperty\' => TypesNamespaceCasts\Bar)', + "array{\0TypesNamespaceCasts\\Foo\0foo: TypesNamespaceCasts\\Foo, \0TypesNamespaceCasts\\Foo\0int: int, \0*\0protectedInt: int, publicInt: int, \0TypesNamespaceCasts\\Bar\0barProperty: TypesNamespaceCasts\\Bar}", '(array) $foo', ], [ - 'array(1, 2, 3)', + 'array{1, 2, 3}', '(array) [1, 2, 3]', ], [ - 'array(1)', + 'array{1}', '(array) 1', ], [ - 'array(1.0)', + 'array{1.0}', '(array) 1.0', ], [ - 'array(true)', + 'array{true}', '(array) true', ], [ - 'array(\'blabla\')', + 'array{\'blabla\'}', '(array) "blabla"', ], [ - 'array(int)', + 'array{int}', '(array) $castedInteger', ], [ @@ -1691,7 +1691,7 @@ public function dataDeductedTypes(): array '$newStatic', ], [ - 'array()', + 'array{}', '$arrayLiteral', ], [ @@ -1723,7 +1723,7 @@ public function dataDeductedTypes(): array 'self::STRING_CONSTANT', ], [ - 'array()', + 'array{}', 'self::ARRAY_CONSTANT', ], [ @@ -1747,7 +1747,7 @@ public function dataDeductedTypes(): array '$foo::STRING_CONSTANT', ], [ - 'array()', + 'array{}', '$foo::ARRAY_CONSTANT', ], [ @@ -2382,7 +2382,7 @@ public function dataBinaryOperations(): array 'min([1, 2, 3])', ], [ - 'array(1, 2, 3)', + 'array{1, 2, 3}', 'min([1, 2, 3], [4, 5, 5])', ], [ @@ -2398,11 +2398,11 @@ public function dataBinaryOperations(): array 'min(0, ...[1, 2, 3])', ], [ - 'array(5, 6, 9)', + 'array{5, 6, 9}', 'max([1, 10, 8], [5, 6, 9])', ], [ - 'array(1, 1, 1, 1)', + 'array{1, 1, 1, 1}', 'max(array(2, 2, 2), array(1, 1, 1, 1))', ], [ @@ -2630,23 +2630,23 @@ public function dataBinaryOperations(): array '!empty($foo)', ], [ - 'array(int, int, int)', + 'array{int, int, int}', '$arrayOfIntegers + $arrayOfIntegers', ], [ - 'array(int, int, int)', + 'array{int, int, int}', '$arrayOfIntegers += $arrayOfIntegers', ], [ - 'array(0 => 1, 1 => 1, 2 => 1, 3 => 1|2, 4 => 1|3, ?5 => 2|3, ?6 => 3)', + 'array{0: 1, 1: 1, 2: 1, 3: 1|2, 4: 1|3, 5?: 2|3, 6?: 3}', '$conditionalArray + $unshiftedConditionalArray', ], [ - 'array(0 => \'lorem\', 1 => stdClass, 2 => 1, 3 => 1, 4 => 1, ?5 => 2|3, ?6 => 3)', + 'array{0: \'lorem\', 1: stdClass, 2: 1, 3: 1, 4: 1, 5?: 2|3, 6?: 3}', '$unshiftedConditionalArray + $conditionalArray', ], [ - 'array(int, int, int)', + 'array{int, int, int}', '$arrayOfIntegers += ["foo"]', ], [ @@ -2658,7 +2658,7 @@ public function dataBinaryOperations(): array '@count($arrayOfIntegers)', ], [ - 'array(int, int, int)', + 'array{int, int, int}', '$anotherArray = $arrayOfIntegers', ], [ @@ -2758,15 +2758,15 @@ public function dataBinaryOperations(): array '$preIncArray[3]', ], [ - 'array(1 => 1, 2 => 2)', + 'array{1: 1, 2: 2}', '$preIncArray', ], [ - 'array(0 => 1, 2 => 3)', + 'array{0: 1, 2: 3}', '$postIncArray', ], [ - 'array(0 => array(1 => array(2 => 3)), 4 => array(5 => array(6 => 7)))', + 'array{0: array{1: array{2: 3}}, 4: array{5: array{6: 7}}}', '$anotherPostIncArray', ], [ @@ -2826,7 +2826,7 @@ public function dataBinaryOperations(): array '1 + "blabla"', ], [ - 'array(1, 2, 3)', + 'array{1, 2, 3}', '[1, 2, 3] + [4, 5, 6]', ], [ @@ -2990,7 +2990,7 @@ public function dataBinaryOperations(): array '$arrToPush2', ], [ - 'array(0 => \'lorem\', 1 => 5, \'foo\' => stdClass, 2 => \'test\')', + 'array{0: \'lorem\', 1: 5, foo: stdClass, 2: \'test\'}', '$arrToUnshift', ], [ @@ -2998,11 +2998,11 @@ public function dataBinaryOperations(): array '$arrToUnshift2', ], [ - 'array(0 => \'lorem\', 1 => stdClass, 2 => 1, 3 => 1, 4 => 1, ?5 => 2|3, ?6 => 3)', + 'array{0: \'lorem\', 1: stdClass, 2: 1, 3: 1, 4: 1, 5?: 2|3, 6?: 3}', '$unshiftedConditionalArray', ], [ - 'array(\'dirname\' => string, \'basename\' => string, \'filename\' => string, ?\'extension\' => string)', + 'array{dirname: string, basename: string, filename: string, extension?: string}', 'pathinfo($string)', ], [ @@ -3106,11 +3106,11 @@ public function dataBinaryOperations(): array 'in_array(\'baz\', [\'foo\', \'bar\'], true)', ], [ - 'array(2, 3)', + 'array{2, 3}', '$arrToShift', ], [ - 'array(1, 2)', + 'array{1, 2}', '$arrToPop', ], [ @@ -3158,7 +3158,7 @@ public function dataBinaryOperations(): array "sprintf('%s %s', 'foo', 'bar')", ], [ - 'array()|array(0 => \'password\'|\'username\', ?1 => \'password\')', + 'array{}|array{0: \'password\'|\'username\', 1?: \'password\'}', '$coalesceArray', ], [ @@ -3315,7 +3315,7 @@ public function dataLiteralArrays(): array '$integers[0] >= $integers[1] - 1', ], [ - 'array(\'foo\' => array(\'foo\' => array(\'foo\' => \'bar\')), \'bar\' => array(), \'baz\' => array(\'lorem\' => array()))', + 'array{foo: array{foo: array{foo: \'bar\'}}, bar: array{}, baz: array{lorem: array{}}}', '$nestedArray', ], [ @@ -4615,7 +4615,7 @@ public function dataArrayFunctions(): array '$integers[0]', ], [ - 'array(string, string, string)', + 'array{string, string, string}', '$mappedStrings', ], [ @@ -4667,7 +4667,7 @@ public function dataArrayFunctions(): array 'array_combine($array, $array2)', ], [ - 'array(1 => 2)', + 'array{1: 2}', 'array_combine([1], [2])', ], [ @@ -4675,7 +4675,7 @@ public function dataArrayFunctions(): array 'array_combine([1, 2], [3])', ], [ - 'array(\'a\' => \'d\', \'b\' => \'e\', \'c\' => \'f\')', + 'array{a: \'d\', b: \'e\', c: \'f\'}', 'array_combine([\'a\', \'b\', \'c\'], [\'d\', \'e\', \'f\'])', ], [ @@ -4767,15 +4767,15 @@ public function dataArrayFunctions(): array 'array_uintersect($integers, [])', ], [ - 'array(1, 1, 1, 1, 1)', + 'array{1, 1, 1, 1, 1}', '$filledIntegers', ], [ - 'array()', + 'array{}', '$emptyFilled', ], [ - 'array(1)', + 'array{1}', '$filledIntegersWithKeys', ], [ @@ -4799,15 +4799,15 @@ public function dataArrayFunctions(): array '$filledByPositiveRange', ], [ - 'array(1, 2)', + 'array{1, 2}', 'array_keys($integerKeys)', ], [ - 'array(\'foo\', \'bar\')', + 'array{\'foo\', \'bar\'}', 'array_keys($stringKeys)', ], [ - 'array(\'foo\', 1)', + 'array{\'foo\', 1}', 'array_keys($stringOrIntegerKeys)', ], [ @@ -4815,7 +4815,7 @@ public function dataArrayFunctions(): array 'array_keys($generalStringKeys)', ], [ - 'array(\'foo\', stdClass)', + 'array{\'foo\', stdClass}', 'array_values($integerKeys)', ], [ @@ -4859,7 +4859,7 @@ public function dataArrayFunctions(): array '$mergedInts', ], [ - 'array(5 => \'banana\', 6 => \'banana\', 7 => \'banana\', 8 => \'banana\', 9 => \'banana\', 10 => \'banana\')', + 'array{5: \'banana\', 6: \'banana\', 7: \'banana\', 8: \'banana\', 9: \'banana\', 10: \'banana\'}', 'array_fill(5, 6, \'banana\')', ], [ @@ -4867,7 +4867,7 @@ public function dataArrayFunctions(): array 'array_fill(0, 101, \'apple\')', ], [ - 'array(-2 => \'pear\', 0 => \'pear\', 1 => \'pear\', 2 => \'pear\')', + 'array{-2: \'pear\', 0: \'pear\', 1: \'pear\', 2: \'pear\'}', 'array_fill(-2, 4, \'pear\')', ], [ @@ -4883,7 +4883,7 @@ public function dataArrayFunctions(): array 'array_fill_keys($generalStringKeys, new \stdClass())', ], [ - 'array(\'foo\' => \'banana\', 5 => \'banana\', 10 => \'banana\', \'bar\' => \'banana\')', + 'array{foo: \'banana\', 5: \'banana\', 10: \'banana\', bar: \'banana\'}', 'array_fill_keys([\'foo\', 5, 10, \'bar\'], \'banana\')', ], [ @@ -4903,11 +4903,11 @@ public function dataArrayFunctions(): array '$unknownArray', ], [ - 'array(\'foo\' => \'banana\', \'bar\' => \'banana\', ?\'baz\' => \'banana\', ?\'lorem\' => \'banana\')', + 'array{foo: \'banana\', bar: \'banana\', baz?: \'banana\', lorem?: \'banana\'}', 'array_fill_keys($conditionalArray, \'banana\')', ], [ - 'array(\'foo\' => stdClass, \'bar\' => stdClass, ?\'baz\' => stdClass, ?\'lorem\' => stdClass)', + 'array{foo: stdClass, bar: stdClass, baz?: stdClass, lorem?: stdClass}', 'array_map(function (): \stdClass {}, $conditionalKeysArray)', ], [ @@ -4943,11 +4943,11 @@ public function dataArrayFunctions(): array 'array_shift([])', ], [ - 'array(null, \'\', 1)', + 'array{null, \'\', 1}', '$constantArrayWithFalseyValues', ], [ - 'array(2 => 1)', + 'array{2: 1}', '$constantTruthyValues', ], [ @@ -4955,7 +4955,7 @@ public function dataArrayFunctions(): array '$falsey', ], [ - 'array()', + 'array{}', 'array_filter($falsey)', ], [ @@ -4967,11 +4967,11 @@ public function dataArrayFunctions(): array 'array_filter($withFalsey)', ], [ - 'array(\'a\' => 1)', + 'array{a: 1}', 'array_filter($union)', ], [ - 'array(?0 => true, ?1 => int<min, -1>|int<1, max>)', + 'array{0?: true, 1?: int<min, -1>|int<1, max>}', 'array_filter($withPossiblyFalsey)', ], [ @@ -5159,55 +5159,55 @@ public function dataArrayFunctions(): array 'array_slice($unknownArray, -2, 1, true)', ], [ - 'array(0 => bool, 1 => int, 2 => \'\', \'a\' => 0)', + 'array{0: bool, 1: int, 2: \'\', a: 0}', 'array_slice($withPossiblyFalsey, 0)', ], [ - 'array(0 => int, 1 => \'\', \'a\' => 0)', + 'array{0: int, 1: \'\', a: 0}', 'array_slice($withPossiblyFalsey, 1)', ], [ - 'array(1 => int, 2 => \'\', \'a\' => 0)', + 'array{1: int, 2: \'\', a: 0}', 'array_slice($withPossiblyFalsey, 1, null, true)', ], [ - 'array(0 => \'\', \'a\' => 0)', + 'array{0: \'\', a: 0}', 'array_slice($withPossiblyFalsey, 2, 3)', ], [ - 'array(2 => \'\', \'a\' => 0)', + 'array{2: \'\', a: 0}', 'array_slice($withPossiblyFalsey, 2, 3, true)', ], [ - 'array(int, \'\')', + 'array{int, \'\'}', 'array_slice($withPossiblyFalsey, 1, -1)', ], [ - 'array(1 => int, 2 => \'\')', + 'array{1: int, 2: \'\'}', 'array_slice($withPossiblyFalsey, 1, -1, true)', ], [ - 'array(0 => \'\', \'a\' => 0)', + 'array{0: \'\', a: 0}', 'array_slice($withPossiblyFalsey, -2, null)', ], [ - 'array(2 => \'\', \'a\' => 0)', + 'array{2: \'\', a: 0}', 'array_slice($withPossiblyFalsey, -2, null, true)', ], [ - 'array(\'baz\' => \'qux\')|array(0 => \'\', \'a\' => 0)', + 'array{0: \'\', a: 0}|array{baz: \'qux\'}', 'array_slice($unionArrays, 1)', ], [ - 'array(\'a\' => 0)|array(\'baz\' => \'qux\')', + 'array{a: 0}|array{baz: \'qux\'}', 'array_slice($unionArrays, -1, null, true)', ], [ - 'array(0 => \'foo\', 1 => \'bar\', \'baz\' => \'qux\', 2 => \'quux\', \'quuz\' => \'corge\', 3 => \'grault\')', + 'array{0: \'foo\', 1: \'bar\', baz: \'qux\', 2: \'quux\', quuz: \'corge\', 3: \'grault\'}', '$slicedOffset', ], [ - 'array(4 => \'foo\', 1 => \'bar\', \'baz\' => \'qux\', 0 => \'quux\', \'quuz\' => \'corge\', 5 => \'grault\')', + 'array{4: \'foo\', 1: \'bar\', baz: \'qux\', 0: \'quux\', quuz: \'corge\', 5: \'grault\'}', '$slicedOffsetWithKeys', ], [ @@ -5530,11 +5530,11 @@ public function dataFunctions(): array '$mbOrdWithUnknownEncoding', ], [ - 'array(\'sec\' => int, \'usec\' => int, \'minuteswest\' => int, \'dsttime\' => int)', + 'array{sec: int, usec: int, minuteswest: int, dsttime: int}', '$gettimeofdayArrayWithoutArg', ], [ - 'array(\'sec\' => int, \'usec\' => int, \'minuteswest\' => int, \'dsttime\' => int)', + 'array{sec: int, usec: int, minuteswest: int, dsttime: int}', '$gettimeofdayArray', ], [ @@ -5542,11 +5542,11 @@ public function dataFunctions(): array '$gettimeofdayFloat', ], [ - 'array(\'sec\' => int, \'usec\' => int, \'minuteswest\' => int, \'dsttime\' => int)|float', + 'array{sec: int, usec: int, minuteswest: int, dsttime: int}|float', '$gettimeofdayDefault', ], [ - '(array(\'sec\' => int, \'usec\' => int, \'minuteswest\' => int, \'dsttime\' => int)|float)', + '(array{sec: int, usec: int, minuteswest: int, dsttime: int}|float)', '$gettimeofdayBenevolent', ], [ @@ -5554,7 +5554,7 @@ public function dataFunctions(): array '$strSplitConstantStringWithoutDefinedParameters', ], [ - "array('a', 'b', 'c', 'd', 'e', 'f')", + 'array{\'a\', \'b\', \'c\', \'d\', \'e\', \'f\'}', '$strSplitConstantStringWithoutDefinedSplitLength', ], [ @@ -5562,11 +5562,11 @@ public function dataFunctions(): array '$strSplitStringWithoutDefinedSplitLength', ], [ - "array('a', 'b', 'c', 'd', 'e', 'f')", + 'array{\'a\', \'b\', \'c\', \'d\', \'e\', \'f\'}', '$strSplitConstantStringWithOneSplitLength', ], [ - "array('abcdef')", + 'array{\'abcdef\'}', '$strSplitConstantStringWithGreaterSplitLengthThanStringLength', ], [ @@ -5591,15 +5591,15 @@ public function dataFunctions(): array '$parseUrlWithoutParameters', ], [ - "array('scheme' => 'http', 'host' => 'abc.def')", + 'array{scheme: \'http\', host: \'abc.def\'}', '$parseUrlConstantUrlWithoutComponent1', ], [ - "array('scheme' => 'http', 'host' => 'def.abc')", + 'array{scheme: \'http\', host: \'def.abc\'}', '$parseUrlConstantUrlWithoutComponent2', ], [ - "array(?'scheme' => string, ?'host' => string, ?'port' => int, ?'user' => string, ?'pass' => string, ?'path' => string, ?'query' => string, ?'fragment' => string)|false", + 'array{scheme?: string, host?: string, port?: int, user?: string, pass?: string, path?: string, query?: string, fragment?: string}|false', '$parseUrlConstantUrlUnknownComponent', ], [ @@ -5623,11 +5623,11 @@ public function dataFunctions(): array '$parseUrlStringUrlWithComponentPort', ], [ - "array(?'scheme' => string, ?'host' => string, ?'port' => int, ?'user' => string, ?'pass' => string, ?'path' => string, ?'query' => string, ?'fragment' => string)|false", + 'array{scheme?: string, host?: string, port?: int, user?: string, pass?: string, path?: string, query?: string, fragment?: string}|false', '$parseUrlStringUrlWithoutComponent', ], [ - "array('path' => 'abc.def')", + 'array{path: \'abc.def\'}', "parse_url('abc.def')", ], [ @@ -5639,15 +5639,15 @@ public function dataFunctions(): array "parse_url('http://abc.def', PHP_URL_SCHEME)", ], [ - 'array(0 => int, 1 => int, 2 => int, 3 => int, 4 => int, 5 => int, 6 => int, 7 => int, 8 => int, 9 => int, 10 => int, 11 => int, 12 => int, \'dev\' => int, \'ino\' => int, \'mode\' => int, \'nlink\' => int, \'uid\' => int, \'gid\' => int, \'rdev\' => int, \'size\' => int, \'atime\' => int, \'mtime\' => int, \'ctime\' => int, \'blksize\' => int, \'blocks\' => int)|false', + 'array{0: int, 1: int, 2: int, 3: int, 4: int, 5: int, 6: int, 7: int, 8: int, 9: int, 10: int, 11: int, 12: int, dev: int, ino: int, mode: int, nlink: int, uid: int, gid: int, rdev: int, size: int, atime: int, mtime: int, ctime: int, blksize: int, blocks: int}|false', '$stat', ], [ - 'array(0 => int, 1 => int, 2 => int, 3 => int, 4 => int, 5 => int, 6 => int, 7 => int, 8 => int, 9 => int, 10 => int, 11 => int, 12 => int, \'dev\' => int, \'ino\' => int, \'mode\' => int, \'nlink\' => int, \'uid\' => int, \'gid\' => int, \'rdev\' => int, \'size\' => int, \'atime\' => int, \'mtime\' => int, \'ctime\' => int, \'blksize\' => int, \'blocks\' => int)|false', + 'array{0: int, 1: int, 2: int, 3: int, 4: int, 5: int, 6: int, 7: int, 8: int, 9: int, 10: int, 11: int, 12: int, dev: int, ino: int, mode: int, nlink: int, uid: int, gid: int, rdev: int, size: int, atime: int, mtime: int, ctime: int, blksize: int, blocks: int}|false', '$lstat', ], [ - 'array(0 => int, 1 => int, 2 => int, 3 => int, 4 => int, 5 => int, 6 => int, 7 => int, 8 => int, 9 => int, 10 => int, 11 => int, 12 => int, \'dev\' => int, \'ino\' => int, \'mode\' => int, \'nlink\' => int, \'uid\' => int, \'gid\' => int, \'rdev\' => int, \'size\' => int, \'atime\' => int, \'mtime\' => int, \'ctime\' => int, \'blksize\' => int, \'blocks\' => int)|false', + 'array{0: int, 1: int, 2: int, 3: int, 4: int, 5: int, 6: int, 7: int, 8: int, 9: int, 10: int, 11: int, 12: int, dev: int, ino: int, mode: int, nlink: int, uid: int, gid: int, rdev: int, size: int, atime: int, mtime: int, ctime: int, blksize: int, blocks: int}|false', '$fstat', ], [ @@ -5786,7 +5786,7 @@ public function dataDioFunctions(): array { return [ [ - 'array(\'device\' => int, \'inode\' => int, \'mode\' => int, \'nlink\' => int, \'uid\' => int, \'gid\' => int, \'device_type\' => int, \'size\' => int, \'blocksize\' => int, \'blocks\' => int, \'atime\' => int, \'mtime\' => int, \'ctime\' => int)|null', + 'array{device: int, inode: int, mode: int, nlink: int, uid: int, gid: int, device_type: int, size: int, blocksize: int, blocks: int, atime: int, mtime: int, ctime: int}|null', '$stat', ], ]; @@ -5816,7 +5816,7 @@ public function dataSsh2Functions(): array { return [ [ - 'array(0 => int, 1 => int, 2 => int, 3 => int, 4 => int, 5 => int, 6 => int, 7 => int, 8 => int, 9 => int, 10 => int, 11 => int, 12 => int, \'dev\' => int, \'ino\' => int, \'mode\' => int, \'nlink\' => int, \'uid\' => int, \'gid\' => int, \'rdev\' => int, \'size\' => int, \'atime\' => int, \'mtime\' => int, \'ctime\' => int, \'blksize\' => int, \'blocks\' => int)|false', + 'array{0: int, 1: int, 2: int, 3: int, 4: int, 5: int, 6: int, 7: int, 8: int, 9: int, 10: int, 11: int, 12: int, dev: int, ino: int, mode: int, nlink: int, uid: int, gid: int, rdev: int, size: int, atime: int, mtime: int, ctime: int, blksize: int, blocks: int}|false', '$ssh2SftpStat', ], ]; @@ -5843,19 +5843,19 @@ public function dataRangeFunction(): array { return [ [ - 'array(2, 3, 4, 5)', + 'array{2, 3, 4, 5}', 'range(2, 5)', ], [ - 'array(2, 4)', + 'array{2, 4}', 'range(2, 5, 2)', ], [ - 'array(2.0, 3.0, 4.0, 5.0)', + 'array{2.0, 3.0, 4.0, 5.0}', 'range(2, 5, 1.0)', ], [ - 'array(2.1, 3.1, 4.1)', + 'array{2.1, 3.1, 4.1}', 'range(2.1, 5)', ], [ @@ -5875,15 +5875,15 @@ public function dataRangeFunction(): array 'range($integer, $mixed)', ], [ - 'array(0 => 1, ?1 => 2)', + 'array{0: 1, 1?: 2}', 'range(1, doFoo() ? 1 : 2)', ], [ - 'array(0 => -1|1, ?1 => 0|2, ?2 => 1, ?3 => 2)', + 'array{0: -1|1, 1?: 0|2, 2?: 1, 3?: 2}', 'range(doFoo() ? -1 : 1, doFoo() ? 1 : 2)', ], [ - 'array(3, 2, 1, 0, -1)', + 'array{3, 2, 1, 0, -1}', 'range(3, -1)', ], [ @@ -7018,7 +7018,7 @@ public function dataResolveStatic(): array '\ResolveStatic\Bar::create()', ], [ - 'array(\'foo\' => ResolveStatic\Bar)', + 'array{foo: ResolveStatic\\Bar}', '$bar->returnConstantArray()', ], [ @@ -7608,15 +7608,15 @@ public function dataReplaceFunctions(): array '$anotherExpectedString', ], [ - 'array(\'a\' => string, \'b\' => string)', + 'array{a: string, b: string}', '$expectedArray', ], [ - 'array(\'a\' => string, \'b\' => string)|null', + 'array{a: string, b: string}|null', '$expectedArray2', ], [ - 'array(\'a\' => string, \'b\' => string)|null', + 'array{a: string, b: string}|null', '$anotherExpectedArray', ], [ @@ -7636,7 +7636,7 @@ public function dataReplaceFunctions(): array '$anotherExpectedArrayOrString', ], [ - 'array(\'a\' => string, \'b\' => string)|null', + 'array{a: string, b: string}|null', 'preg_replace_callback_array($callbacks, $array)', ], [ @@ -8193,7 +8193,7 @@ public function dataPassedByReference(): array { return [ [ - 'array(1, 2, 3)', + 'array{1, 2, 3}', '$arr', ], [ @@ -8275,7 +8275,7 @@ public function dataArrayKeysInBranches(): array { return [ [ - 'array(\'i\' => int, \'j\' => int, \'k\' => int, \'key\' => DateTimeImmutable, \'l\' => 1, \'m\' => 5, ?\'n\' => \'str\')', + 'array{i: int, j: int, k: int, key: DateTimeImmutable, l: 1, m: 5, n?: \'str\'}', '$array', ], [ @@ -8287,7 +8287,7 @@ public function dataArrayKeysInBranches(): array '$generalArray[\'key\']', ], [ - 'array(0 => \'foo\', 1 => \'bar\', ?2 => \'baz\')', + 'array{0: \'foo\', 1: \'bar\', 2?: \'baz\'}', '$arrayAppendedInIf', ], [ @@ -8680,15 +8680,15 @@ public function dataIsset(): array '$array[\'b\']', ], [ - 'array(\'a\' => 1|2|3, \'b\' => 2|3, ?\'c\' => 4)', + 'array{a: 1|2|3, b: 2|3, c?: 4}', '$array', ], [ - 'array(\'a\' => 1|2|3, \'b\' => 2|3|null, ?\'c\' => 4)', + 'array{a: 1|2|3, b: 2|3|null, c?: 4}', '$arrayCopy', ], [ - 'array(\'a\' => 1|2|3, ?\'c\' => 4)', + 'array{a: 1|2|3, c?: 4}', '$anotherArrayCopy', ], [ @@ -8764,7 +8764,7 @@ public function dataPropertyArrayAssignment(): array "'start'", ], [ - 'array()', + 'array{}', '$this->property', "'emptyArray'", ], @@ -8774,7 +8774,7 @@ public function dataPropertyArrayAssignment(): array "'emptyArray'", ], [ - 'array(\'foo\' => 1)', + 'array{foo: 1}', '$this->property', "'afterAssignment'", ], @@ -9055,11 +9055,11 @@ public function dataPhp73Functions(): array 'array_key_last($anotherLiteralArray)', ], [ - 'array(int, int)', + 'array{int, int}', '$hrtime1', ], [ - 'array(int, int)', + 'array{int, int}', '$hrtime2', ], [ @@ -9067,7 +9067,7 @@ public function dataPhp73Functions(): array '$hrtime3', ], [ - 'array(int, int)|float|int', + 'array{int, int}|float|int', '$hrtime4', ], ]; @@ -9101,7 +9101,7 @@ public function dataPhp74Functions(): array '$mbStrSplitConstantStringWithoutDefinedParameters', ], [ - "array('a', 'b', 'c', 'd', 'e', 'f')", + 'array{\'a\', \'b\', \'c\', \'d\', \'e\', \'f\'}', '$mbStrSplitConstantStringWithoutDefinedSplitLength', ], [ @@ -9109,11 +9109,11 @@ public function dataPhp74Functions(): array '$mbStrSplitStringWithoutDefinedSplitLength', ], [ - "array('a', 'b', 'c', 'd', 'e', 'f')", + 'array{\'a\', \'b\', \'c\', \'d\', \'e\', \'f\'}', '$mbStrSplitConstantStringWithOneSplitLength', ], [ - "array('abcdef')", + 'array{\'abcdef\'}', '$mbStrSplitConstantStringWithGreaterSplitLengthThanStringLength', ], [ @@ -9133,7 +9133,7 @@ public function dataPhp74Functions(): array '$mbStrSplitConstantStringWithVariableStringAndVariableSplitLength', ], [ - "array('a', 'b', 'c', 'd', 'e', 'f')", + "array{'a', 'b', 'c', 'd', 'e', 'f'}", '$mbStrSplitConstantStringWithOneSplitLengthAndValidEncoding', ], [ @@ -9145,7 +9145,7 @@ public function dataPhp74Functions(): array '$mbStrSplitConstantStringWithOneSplitLengthAndVariableEncoding', ], [ - "array('abcdef')", + "array{'abcdef'}", '$mbStrSplitConstantStringWithGreaterSplitLengthThanStringLengthAndValidEncoding', ], [ @@ -9320,7 +9320,7 @@ public function dataGeneralizeScope(): array { return [ [ - "array<array<int|string, array('hitCount' => int, 'loadCount' => int, 'removeCount' => int, 'saveCount' => int)>>", + 'array<array<int|string, array{hitCount: int, loadCount: int, removeCount: int, saveCount: int}>>', '$statistics', ], ]; @@ -9347,7 +9347,7 @@ public function dataGeneralizeScopeRecursiveType(): array { return [ [ - 'array()|array(\'foo\' => array<array>)', + 'array{}|array{foo: array<array>}', '$data', ], ]; @@ -9374,15 +9374,15 @@ public function dataArrayShapesInPhpDoc(): array { return [ [ - 'array(0 => string, 1 => ArrayShapesInPhpDoc\Foo, \'foo\' => ArrayShapesInPhpDoc\Bar, 2 => ArrayShapesInPhpDoc\Baz)', + 'array{0: string, 1: ArrayShapesInPhpDoc\\Foo, foo: ArrayShapesInPhpDoc\\Bar, 2: ArrayShapesInPhpDoc\\Baz}', '$one', ], [ - 'array(0 => string, ?1 => ArrayShapesInPhpDoc\Foo, ?\'foo\' => ArrayShapesInPhpDoc\Bar)', + 'array{0: string, 1?: ArrayShapesInPhpDoc\\Foo, foo?: ArrayShapesInPhpDoc\\Bar}', '$two', ], [ - 'array(?0 => string, ?1 => ArrayShapesInPhpDoc\Foo, ?\'foo\' => ArrayShapesInPhpDoc\Bar)', + 'array{0?: string, 1?: ArrayShapesInPhpDoc\\Foo, foo?: ArrayShapesInPhpDoc\\Bar}', '$three', ], ]; @@ -9510,7 +9510,7 @@ public function dataArrowFunctions(): array '$x()', ], [ - 'array(\'a\' => 1, \'b\' => 2)', + 'array{a: 1, b: 2}', '$y()', ], ]; @@ -9598,11 +9598,11 @@ public function dataCoalesceAssign(): array '$arrayWithMaybeFoo[\'foo\'] ??= \'bar\'', ], [ - 'array(\'foo\' => \'foo\')', + 'array{foo: \'foo\'}', '$arrayAfterAssignment', ], [ - 'array(\'foo\' => \'foo\')', + 'array{foo: \'foo\'}', '$arrayWithFooAfterAssignment', ], [ @@ -9648,7 +9648,7 @@ public function dataArraySpread(): array '$integersTwo', ], [ - 'array(1, 2, 3, 4, 5, 6, 7)', + 'array{1, 2, 3, 4, 5, 6, 7}', '$integersThree', ], [ @@ -9660,11 +9660,11 @@ public function dataArraySpread(): array '$integersFive', ], [ - 'array(1, 2, 3, 4, 5, 6, 7)', + 'array{1, 2, 3, 4, 5, 6, 7}', '$integersSix', ], [ - 'array(1, 2, 3, 4, 5, 6, 7)', + 'array{1, 2, 3, 4, 5, 6, 7}', '$integersSeven', ], ]; diff --git a/tests/PHPStan/Analyser/ScopeTest.php b/tests/PHPStan/Analyser/ScopeTest.php index c6509673e0..7c016efeb3 100644 --- a/tests/PHPStan/Analyser/ScopeTest.php +++ b/tests/PHPStan/Analyser/ScopeTest.php @@ -106,7 +106,7 @@ public function dataGeneralize(): array ], [ new ConstantIntegerType(1), ]), - 'array(\'a\' => 1)', + 'array{a: 1}', ], [ new ConstantArrayType([ @@ -123,7 +123,7 @@ public function dataGeneralize(): array new ConstantIntegerType(2), new ConstantIntegerType(1), ]), - 'array(\'a\' => int, \'b\' => 1)', + 'array{a: int, b: 1}', ], [ new ConstantArrayType([ diff --git a/tests/PHPStan/Analyser/TypeSpecifierTest.php b/tests/PHPStan/Analyser/TypeSpecifierTest.php index fce28bca4f..a9aae5e04e 100644 --- a/tests/PHPStan/Analyser/TypeSpecifierTest.php +++ b/tests/PHPStan/Analyser/TypeSpecifierTest.php @@ -30,7 +30,7 @@ class TypeSpecifierTest extends \PHPStan\Testing\PHPStanTestCase { - private const FALSEY_TYPE_DESCRIPTION = '0|0.0|\'\'|\'0\'|array()|false|null'; + private const FALSEY_TYPE_DESCRIPTION = '0|0.0|\'\'|\'0\'|array{}|false|null'; private const TRUTHY_TYPE_DESCRIPTION = 'mixed~' . self::FALSEY_TYPE_DESCRIPTION; private const SURE_NOT_FALSEY = '~' . self::FALSEY_TYPE_DESCRIPTION; private const SURE_NOT_TRUTHY = '~' . self::TRUTHY_TYPE_DESCRIPTION; @@ -533,7 +533,7 @@ public function dataCondition(): array [ new Expr\BooleanNot(new Expr\Empty_(new Variable('stringOrNull'))), [ - '$stringOrNull' => '~0|0.0|\'\'|\'0\'|array()|false|null', + '$stringOrNull' => '~0|0.0|\'\'|\'0\'|array{}|false|null', ], [], ], @@ -552,13 +552,13 @@ public function dataCondition(): array new Expr\Empty_(new Variable('array')), [], [ - '$array' => '~0|0.0|\'\'|\'0\'|array()|false|null', + '$array' => '~0|0.0|\'\'|\'0\'|array{}|false|null', ], ], [ new BooleanNot(new Expr\Empty_(new Variable('array'))), [ - '$array' => '~0|0.0|\'\'|\'0\'|array()|false|null', + '$array' => '~0|0.0|\'\'|\'0\'|array{}|false|null', ], [], ], diff --git a/tests/PHPStan/Analyser/data/array-shapes-keys-strings.php b/tests/PHPStan/Analyser/data/array-shapes-keys-strings.php index 8d515c924b..c757be702d 100644 --- a/tests/PHPStan/Analyser/data/array-shapes-keys-strings.php +++ b/tests/PHPStan/Analyser/data/array-shapes-keys-strings.php @@ -17,8 +17,8 @@ class Foo */ public function doFoo(array $slash, array $dollar): void { - assertType("array('namespace/key' => string)", $slash); - assertType('array<int, array(\'$ref\' => string)>', $dollar); + assertType('array{namespace/key: string}', $slash); + assertType('array<int, array{$ref: string}>', $dollar); } } diff --git a/tests/PHPStan/Analyser/data/array_map_multiple.php b/tests/PHPStan/Analyser/data/array_map_multiple.php index 381bccec47..ce73048a46 100644 --- a/tests/PHPStan/Analyser/data/array_map_multiple.php +++ b/tests/PHPStan/Analyser/data/array_map_multiple.php @@ -24,13 +24,13 @@ public function doFoo(int $i, string $s): void */ public function arrayMapNull(array $array, array $other): void { - assertType('array()', array_map(null, [])); - assertType('array(\'foo\' => true)', array_map(null, ['foo' => true])); - assertType('non-empty-array<int, array(1|2|3, 4|5|6)>', array_map(null, [1, 2, 3], [4, 5, 6])); + assertType('array{}', array_map(null, [])); + assertType('array{foo: true}', array_map(null, ['foo' => true])); + assertType('non-empty-array<int, array{1|2|3, 4|5|6}>', array_map(null, [1, 2, 3], [4, 5, 6])); assertType('non-empty-array<string, int>', array_map(null, $array)); - assertType('non-empty-array<int, array(int, int)>', array_map(null, $array, $array)); - assertType('non-empty-array<int, array(int, bool)>', array_map(null, $array, $other)); + assertType('non-empty-array<int, array{int, int}>', array_map(null, $array, $array)); + assertType('non-empty-array<int, array{int, bool}>', array_map(null, $array, $other)); } } diff --git a/tests/PHPStan/Analyser/data/arrow-function-types.php b/tests/PHPStan/Analyser/data/arrow-function-types.php index 3ea7bf5f07..77cbe12cf8 100644 --- a/tests/PHPStan/Analyser/data/arrow-function-types.php +++ b/tests/PHPStan/Analyser/data/arrow-function-types.php @@ -12,33 +12,33 @@ class Foo public function doFoo(): void { - array_map(fn(array $a): array => assertType('array(\'foo\' => string, \'bar\' => int)', $a), $this->arrayShapes); + array_map(fn(array $a): array => assertType('array{foo: string, bar: int}', $a), $this->arrayShapes); $a = array_map(fn(array $a) => $a, $this->arrayShapes); - assertType('array<int, array(\'foo\' => string, \'bar\' => int)>', $a); + assertType('array<int, array{foo: string, bar: int}>', $a); - array_map(fn($b) => assertType('array(\'foo\' => string, \'bar\' => int)', $b), $this->arrayShapes); + array_map(fn($b) => assertType('array{foo: string, bar: int}', $b), $this->arrayShapes); $b = array_map(fn($b) => $b['foo'], $this->arrayShapes); assertType('array<int, string>', $b); } public function doBar(): void { - usort($this->arrayShapes, fn(array $a, array $b): int => assertType('array(\'foo\' => string, \'bar\' => int)', $a)); + usort($this->arrayShapes, fn(array $a, array $b): int => assertType('array{foo: string, bar: int}', $a)); } public function doBar2(): void { - usort($this->arrayShapes, fn (array $a, array $b): int => assertType('array(\'foo\' => string, \'bar\' => int)', $b)); + usort($this->arrayShapes, fn (array $a, array $b): int => assertType('array{foo: string, bar: int}', $b)); } public function doBaz(): void { - usort($this->arrayShapes, fn ($a, $b): int => assertType('array(\'foo\' => string, \'bar\' => int)', $a)); + usort($this->arrayShapes, fn ($a, $b): int => assertType('array{foo: string, bar: int}', $a)); } public function doBaz2(): void { - usort($this->arrayShapes, fn ($a, $b): int => assertType('array(\'foo\' => string, \'bar\' => int)', $b)); + usort($this->arrayShapes, fn ($a, $b): int => assertType('array{foo: string, bar: int}', $b)); } } diff --git a/tests/PHPStan/Analyser/data/assign-nested-arrays.php b/tests/PHPStan/Analyser/data/assign-nested-arrays.php index 8463b19c6e..31cecaa4d1 100644 --- a/tests/PHPStan/Analyser/data/assign-nested-arrays.php +++ b/tests/PHPStan/Analyser/data/assign-nested-arrays.php @@ -14,7 +14,7 @@ public function doFoo(int $i) $array[$i]['bar'] = 1; $array[$i]['baz'] = 2; - assertType('non-empty-array<int, array(\'bar\' => 1, \'baz\' => 2)>', $array); + assertType('non-empty-array<int, array{bar: 1, baz: 2}>', $array); } public function doBar(int $i, int $j) @@ -27,7 +27,7 @@ public function doBar(int $i, int $j) echo $array[$i][$j]['bar']; echo $array[$i][$j]['baz']; - assertType('non-empty-array<int, non-empty-array<int, array(\'bar\' => 1, \'baz\' => 2)>>', $array); + assertType('non-empty-array<int, non-empty-array<int, array{bar: 1, baz: 2}>>', $array); } } diff --git a/tests/PHPStan/Analyser/data/bug-1283.php b/tests/PHPStan/Analyser/data/bug-1283.php index fb1e5a2e0e..058c739bb9 100644 --- a/tests/PHPStan/Analyser/data/bug-1283.php +++ b/tests/PHPStan/Analyser/data/bug-1283.php @@ -21,7 +21,7 @@ function (array $levels): void { throw new \UnexpectedValueException(sprintf('Unsupported level `%s`', $level)); } - assertType('array(0 => 1, ?1 => 3)', $allowedElements); + assertType('array{0: 1, 1?: 3}', $allowedElements); assertVariableCertainty(TrinaryLogic::createYes(), $allowedElements); } }; diff --git a/tests/PHPStan/Analyser/data/bug-1861.php b/tests/PHPStan/Analyser/data/bug-1861.php index c7bbcc29f7..4d5335a67c 100644 --- a/tests/PHPStan/Analyser/data/bug-1861.php +++ b/tests/PHPStan/Analyser/data/bug-1861.php @@ -15,7 +15,7 @@ public function isPath(): void { switch (count($this->children)) { case 0: - assertType('array()', $this->children); + assertType('array{}', $this->children); break; case 1: assertType('non-empty-array<' . self::class . '>', $this->children); diff --git a/tests/PHPStan/Analyser/data/bug-1924.php b/tests/PHPStan/Analyser/data/bug-1924.php index 048ccd3ff6..05c13dab62 100644 --- a/tests/PHPStan/Analyser/data/bug-1924.php +++ b/tests/PHPStan/Analyser/data/bug-1924.php @@ -18,7 +18,7 @@ function foo(): void 'a' => $this->getArrayOrNull(), 'b' => $this->getArrayOrNull(), ]; - assertType('array(\'a\' => array|null, \'b\' => array|null)', $arr); + assertType('array{a: array|null, b: array|null}', $arr); $cond = isset($arr['a']) && isset($arr['b']); assertType('bool', $cond); diff --git a/tests/PHPStan/Analyser/data/bug-2001.php b/tests/PHPStan/Analyser/data/bug-2001.php index 01ff5a4113..22db42086a 100644 --- a/tests/PHPStan/Analyser/data/bug-2001.php +++ b/tests/PHPStan/Analyser/data/bug-2001.php @@ -9,28 +9,28 @@ class HelloWorld public function parseUrl(string $url): string { $parsedUrl = parse_url(urldecode($url)); - assertType('array(?\'scheme\' => string, ?\'host\' => string, ?\'port\' => int, ?\'user\' => string, ?\'pass\' => string, ?\'path\' => string, ?\'query\' => string, ?\'fragment\' => string)|false', $parsedUrl); + assertType('array{scheme?: string, host?: string, port?: int, user?: string, pass?: string, path?: string, query?: string, fragment?: string}|false', $parsedUrl); if (array_key_exists('host', $parsedUrl)) { - assertType('array(?\'scheme\' => string, \'host\' => string, ?\'port\' => int, ?\'user\' => string, ?\'pass\' => string, ?\'path\' => string, ?\'query\' => string, ?\'fragment\' => string)', $parsedUrl); + assertType('array{scheme?: string, host: string, port?: int, user?: string, pass?: string, path?: string, query?: string, fragment?: string}', $parsedUrl); throw new \RuntimeException('Absolute URLs are prohibited for the redirectTo parameter.'); } - assertType('array(?\'scheme\' => string, ?\'port\' => int, ?\'user\' => string, ?\'pass\' => string, ?\'path\' => string, ?\'query\' => string, ?\'fragment\' => string)|false', $parsedUrl); + assertType('array{scheme?: string, port?: int, user?: string, pass?: string, path?: string, query?: string, fragment?: string}|false', $parsedUrl); $redirectUrl = $parsedUrl['path']; if (array_key_exists('query', $parsedUrl)) { - assertType('array(?\'scheme\' => string, ?\'port\' => int, ?\'user\' => string, ?\'pass\' => string, ?\'path\' => string, \'query\' => string, ?\'fragment\' => string)', $parsedUrl); + assertType('array{scheme?: string, port?: int, user?: string, pass?: string, path?: string, query: string, fragment?: string}', $parsedUrl); $redirectUrl .= '?' . $parsedUrl['query']; } if (array_key_exists('fragment', $parsedUrl)) { - assertType('array(?\'scheme\' => string, ?\'port\' => int, ?\'user\' => string, ?\'pass\' => string, ?\'path\' => string, ?\'query\' => string, \'fragment\' => string)', $parsedUrl); + assertType('array{scheme?: string, port?: int, user?: string, pass?: string, path?: string, query?: string, fragment: string}', $parsedUrl); $redirectUrl .= '#' . $parsedUrl['query']; } - assertType('array(?\'scheme\' => string, ?\'port\' => int, ?\'user\' => string, ?\'pass\' => string, ?\'path\' => string, ?\'query\' => string, ?\'fragment\' => string)|false', $parsedUrl); + assertType('array{scheme?: string, port?: int, user?: string, pass?: string, path?: string, query?: string, fragment?: string}|false', $parsedUrl); return $redirectUrl; } @@ -46,6 +46,6 @@ public function doFoo(int $i) $a = ['d' => $i]; } - assertType('array(\'a\' => int, ?\'b\' => int)|array(\'d\' => int)', $a); + assertType('array{a: int, b?: int}|array{d: int}', $a); } } diff --git a/tests/PHPStan/Analyser/data/bug-2232.php b/tests/PHPStan/Analyser/data/bug-2232.php index 3f1613c725..7464edf141 100644 --- a/tests/PHPStan/Analyser/data/bug-2232.php +++ b/tests/PHPStan/Analyser/data/bug-2232.php @@ -35,5 +35,5 @@ function () { $data['b5'] = "env"; } - assertType('array(\'a1\' => \'a\', \'a2\' => \'b\', \'a3\' => \'c\', \'a4\' => array(\'name\' => \'dsfs\', \'version\' => \'fdsfs\'), ?\'b1\' => \'hello\', ?\'b2\' => \'hello\', ?\'b3\' => \'hello\', ?\'b4\' => \'goodbye\', ?\'b5\' => \'env\')', $data); + assertType('array{a1: \'a\', a2: \'b\', a3: \'c\', a4: array{name: \'dsfs\', version: \'fdsfs\'}, b1?: \'hello\', b2?: \'hello\', b3?: \'hello\', b4?: \'goodbye\', b5?: \'env\'}', $data); }; diff --git a/tests/PHPStan/Analyser/data/bug-2378.php b/tests/PHPStan/Analyser/data/bug-2378.php index ab58f7a28c..d5984a6364 100644 --- a/tests/PHPStan/Analyser/data/bug-2378.php +++ b/tests/PHPStan/Analyser/data/bug-2378.php @@ -14,8 +14,8 @@ public function doFoo( float $f ): void { - assertType('array(\'a\', \'b\', \'c\', \'d\')', range('a', 'd')); - assertType('array(\'a\', \'c\', \'e\', \'g\', \'i\')', range('a', 'i', 2)); + assertType('array{\'a\', \'b\', \'c\', \'d\'}', range('a', 'd')); + assertType('array{\'a\', \'c\', \'e\', \'g\', \'i\'}', range('a', 'i', 2)); assertType('array<int, string>', range($s, $s)); } diff --git a/tests/PHPStan/Analyser/data/bug-2677.php b/tests/PHPStan/Analyser/data/bug-2677.php index c191dd1f3d..22656ae4a3 100644 --- a/tests/PHPStan/Analyser/data/bug-2677.php +++ b/tests/PHPStan/Analyser/data/bug-2677.php @@ -41,7 +41,7 @@ function () O::class, P::class, ]; - assertType('array(\'Bug2677\\\\A\', \'Bug2677\\\\B\', \'Bug2677\\\\C\', \'Bug2677\\\\D\', \'Bug2677\\\\E\', \'Bug2677\\\\F\', \'Bug2677\\\\G\', \'Bug2677\\\\H\', \'Bug2677\\\\I\', \'Bug2677\\\\J\', \'Bug2677\\\\K\', \'Bug2677\\\\L\', \'Bug2677\\\\M\', \'Bug2677\\\\N\', \'Bug2677\\\\O\', \'Bug2677\\\\P\')', $classes); + assertType('array{\'Bug2677\\\\A\', \'Bug2677\\\\B\', \'Bug2677\\\\C\', \'Bug2677\\\\D\', \'Bug2677\\\\E\', \'Bug2677\\\\F\', \'Bug2677\\\\G\', \'Bug2677\\\\H\', \'Bug2677\\\\I\', \'Bug2677\\\\J\', \'Bug2677\\\\K\', \'Bug2677\\\\L\', \'Bug2677\\\\M\', \'Bug2677\\\\N\', \'Bug2677\\\\O\', \'Bug2677\\\\P\'}', $classes); foreach ($classes as $class) { assertType('\'Bug2677\\\\A\'|\'Bug2677\\\\B\'|\'Bug2677\\\\C\'|\'Bug2677\\\\D\'|\'Bug2677\\\\E\'|\'Bug2677\\\\F\'|\'Bug2677\\\\G\'|\'Bug2677\\\\H\'|\'Bug2677\\\\I\'|\'Bug2677\\\\J\'|\'Bug2677\\\\K\'|\'Bug2677\\\\L\'|\'Bug2677\\\\M\'|\'Bug2677\\\\N\'|\'Bug2677\\\\O\'|\'Bug2677\\\\P\'', $class); diff --git a/tests/PHPStan/Analyser/data/bug-2733.php b/tests/PHPStan/Analyser/data/bug-2733.php index d40acdc032..f18f5053d9 100644 --- a/tests/PHPStan/Analyser/data/bug-2733.php +++ b/tests/PHPStan/Analyser/data/bug-2733.php @@ -18,7 +18,7 @@ public function doSomething(array $data): void } } - assertType('array(\'id\' => int, \'name\' => string)', $data); + assertType('array{id: int, name: string}', $data); } } diff --git a/tests/PHPStan/Analyser/data/bug-3009.php b/tests/PHPStan/Analyser/data/bug-3009.php index de9f96ca4c..a0808efd6b 100644 --- a/tests/PHPStan/Analyser/data/bug-3009.php +++ b/tests/PHPStan/Analyser/data/bug-3009.php @@ -11,18 +11,18 @@ public function createRedirectRequest(string $redirectUri): ?string { $redirectUrlParts = parse_url($redirectUri); if (false === is_array($redirectUrlParts) || true === array_key_exists('host', $redirectUrlParts)) { - assertType('array(?\'scheme\' => string, ?\'host\' => string, ?\'port\' => int, ?\'user\' => string, ?\'pass\' => string, ?\'path\' => string, ?\'query\' => string, ?\'fragment\' => string)|false', $redirectUrlParts); + assertType('array{scheme?: string, host?: string, port?: int, user?: string, pass?: string, path?: string, query?: string, fragment?: string}|false', $redirectUrlParts); return null; } - assertType('array(?\'scheme\' => string, ?\'host\' => string, ?\'port\' => int, ?\'user\' => string, ?\'pass\' => string, ?\'path\' => string, ?\'query\' => string, ?\'fragment\' => string)', $redirectUrlParts); + assertType('array{scheme?: string, host?: string, port?: int, user?: string, pass?: string, path?: string, query?: string, fragment?: string}', $redirectUrlParts); if (true === array_key_exists('query', $redirectUrlParts)) { - assertType('array(?\'scheme\' => string, ?\'host\' => string, ?\'port\' => int, ?\'user\' => string, ?\'pass\' => string, ?\'path\' => string, \'query\' => string, ?\'fragment\' => string)', $redirectUrlParts); + assertType('array{scheme?: string, host?: string, port?: int, user?: string, pass?: string, path?: string, query: string, fragment?: string}', $redirectUrlParts); $redirectServer['QUERY_STRING'] = $redirectUrlParts['query']; } - assertType('array(?\'scheme\' => string, ?\'host\' => string, ?\'port\' => int, ?\'user\' => string, ?\'pass\' => string, ?\'path\' => string, ?\'query\' => string, ?\'fragment\' => string)', $redirectUrlParts); + assertType('array{scheme?: string, host?: string, port?: int, user?: string, pass?: string, path?: string, query?: string, fragment?: string}', $redirectUrlParts); return 'foo'; } diff --git a/tests/PHPStan/Analyser/data/bug-3269.php b/tests/PHPStan/Analyser/data/bug-3269.php index b3cfdbea68..f7f5a2bce6 100644 --- a/tests/PHPStan/Analyser/data/bug-3269.php +++ b/tests/PHPStan/Analyser/data/bug-3269.php @@ -20,10 +20,10 @@ public static function bar(array $intervalGroups): void } } - assertType('array<int, array(\'version\' => string, \'operator\' => string, \'side\' => \'end\'|\'start\')>', $borders); + assertType('array<int, array{version: string, operator: string, side: \'end\'|\'start\'}>', $borders); foreach ($borders as $border) { - assertType('array(\'version\' => string, \'operator\' => string, \'side\' => \'end\'|\'start\')', $border); + assertType('array{version: string, operator: string, side: \'end\'|\'start\'}', $border); assertType('\'end\'|\'start\'', $border['side']); } } diff --git a/tests/PHPStan/Analyser/data/bug-3276.php b/tests/PHPStan/Analyser/data/bug-3276.php index dccb79c5fc..ece368c9b1 100644 --- a/tests/PHPStan/Analyser/data/bug-3276.php +++ b/tests/PHPStan/Analyser/data/bug-3276.php @@ -13,7 +13,7 @@ class Foo public function doFoo(array $settings): void { $settings['name'] ??= 'unknown'; - assertType('array(\'name\' => string)', $settings); + assertType('array{name: string}', $settings); } /** @@ -22,7 +22,7 @@ public function doFoo(array $settings): void public function doBar(array $settings): void { $settings['name'] = 'unknown'; - assertType('array(\'name\' => \'unknown\')', $settings); + assertType('array{name: \'unknown\'}', $settings); } } diff --git a/tests/PHPStan/Analyser/data/bug-3351.php b/tests/PHPStan/Analyser/data/bug-3351.php index 83198c9c1d..2de71cddc2 100644 --- a/tests/PHPStan/Analyser/data/bug-3351.php +++ b/tests/PHPStan/Analyser/data/bug-3351.php @@ -12,7 +12,7 @@ public function sayHello(): void $c = $this->combine($a, $b); assertType('array<string, int>|false', $c); - assertType('array(\'a\' => 1, \'b\' => 2, \'c\' => 3)', array_combine($a, $b)); + assertType('array{a: 1, b: 2, c: 3}', array_combine($a, $b)); } /** diff --git a/tests/PHPStan/Analyser/data/bug-3558.php b/tests/PHPStan/Analyser/data/bug-3558.php index 49dd89b06c..b473c961bb 100644 --- a/tests/PHPStan/Analyser/data/bug-3558.php +++ b/tests/PHPStan/Analyser/data/bug-3558.php @@ -14,7 +14,7 @@ function (): void { } if(count($idGroups) > 0){ - assertType('array(array(1, 2), array(1, 2), array(1, 2))', $idGroups); + assertType('array{array{1, 2}, array{1, 2}, array{1, 2}}', $idGroups); } }; @@ -28,6 +28,6 @@ function (): void { } if(count($idGroups) > 1){ - assertType('array(0 => 1, ?1 => array(1, 2), ?2 => array(1, 2), ?3 => array(1, 2))', $idGroups); + assertType('array{0: 1, 1?: array{1, 2}, 2?: array{1, 2}, 3?: array{1, 2}}', $idGroups); } }; diff --git a/tests/PHPStan/Analyser/data/bug-3991.php b/tests/PHPStan/Analyser/data/bug-3991.php index aee3f87ac1..5ce1de9324 100644 --- a/tests/PHPStan/Analyser/data/bug-3991.php +++ b/tests/PHPStan/Analyser/data/bug-3991.php @@ -22,7 +22,7 @@ public static function email($config = null) assertType('array|stdClass|null', $config); $config = new \stdClass(); } elseif (! (is_array($config) || $config instanceof \stdClass)) { - assertNativeType('mixed~0|0.0|\'\'|\'0\'|array()|stdClass|false|null', $config); + assertNativeType('mixed~0|0.0|\'\'|\'0\'|array{}|stdClass|false|null', $config); assertType('*NEVER*', $config); } diff --git a/tests/PHPStan/Analyser/data/bug-4099.php b/tests/PHPStan/Analyser/data/bug-4099.php index 571dfb3476..2e49179969 100644 --- a/tests/PHPStan/Analyser/data/bug-4099.php +++ b/tests/PHPStan/Analyser/data/bug-4099.php @@ -13,7 +13,7 @@ class Foo */ function arrayHint(array $arr): void { - assertType('array(\'key\' => array(\'inner\' => mixed))', $arr); + assertType('array{key: array{inner: mixed}}', $arr); assertNativeType('array', $arr); if (!array_key_exists('key', $arr)) { @@ -21,21 +21,21 @@ function arrayHint(array $arr): void assertNativeType('array', $arr); throw new \Exception('no key "key" found.'); } - assertType('array(\'key\' => array(\'inner\' => mixed))', $arr); + assertType('array{key: array{inner: mixed}}', $arr); assertNativeType('array&hasOffset(\'key\')', $arr); - assertType('array(\'inner\' => mixed)', $arr['key']); + assertType('array{inner: mixed}', $arr['key']); assertNativeType('mixed', $arr['key']); if (!array_key_exists('inner', $arr['key'])) { - assertType('array(\'key\' => *NEVER*)', $arr); + assertType('array{key: *NEVER*}', $arr); //assertNativeType('array(\'key\' => mixed)', $arr); assertType('*NEVER*', $arr['key']); //assertNativeType('mixed', $arr['key']); throw new \Exception('need key.inner'); } - assertType('array(\'key\' => array(\'inner\' => mixed))', $arr); - assertNativeType('array(\'key\' => array(\'inner\' => mixed))', $arr); + assertType('array{key: array{inner: mixed}}', $arr); + assertNativeType('array{key: array{inner: mixed}}', $arr); } } diff --git a/tests/PHPStan/Analyser/data/bug-4213.php b/tests/PHPStan/Analyser/data/bug-4213.php index bc9742be9a..538bacbb79 100644 --- a/tests/PHPStan/Analyser/data/bug-4213.php +++ b/tests/PHPStan/Analyser/data/bug-4213.php @@ -37,7 +37,7 @@ public function setEnumsWithoutSplat(array $enums): void { function (): void { assertType('Bug4213\Enum', Enum::get('test')); - assertType('array(Bug4213\Enum)', array_map([Enum::class, 'get'], ['test'])); + assertType('array{Bug4213\\Enum}', array_map([Enum::class, 'get'], ['test'])); }; diff --git a/tests/PHPStan/Analyser/data/bug-4504.php b/tests/PHPStan/Analyser/data/bug-4504.php index 50ba802671..f70d3c9567 100644 --- a/tests/PHPStan/Analyser/data/bug-4504.php +++ b/tests/PHPStan/Analyser/data/bug-4504.php @@ -14,7 +14,7 @@ public function sayHello($models): void assertType('Bug4504TypeInference\A', $v); } - assertType('array()|Iterator<mixed, Bug4504TypeInference\A>', $models); + assertType('array{}|Iterator<mixed, Bug4504TypeInference\A>', $models); } } diff --git a/tests/PHPStan/Analyser/data/bug-4558.php b/tests/PHPStan/Analyser/data/bug-4558.php index 1c4aba719c..a40e33581a 100644 --- a/tests/PHPStan/Analyser/data/bug-4558.php +++ b/tests/PHPStan/Analyser/data/bug-4558.php @@ -31,7 +31,7 @@ public function sayHello(): ?DateTime // we might be out of suggested days, so load some more if (count($this->suggestions) === 0) { - assertType('array()', $this->suggestions); + assertType('array{}', $this->suggestions); assertType('0', count($this->suggestions)); $this->createSuggestions(); } diff --git a/tests/PHPStan/Analyser/data/bug-4587.php b/tests/PHPStan/Analyser/data/bug-4587.php index 995bdfc7e3..b0643a055e 100644 --- a/tests/PHPStan/Analyser/data/bug-4587.php +++ b/tests/PHPStan/Analyser/data/bug-4587.php @@ -12,11 +12,11 @@ public function a(): void $results = []; $type = array_map(static function (array $result): array { - assertType('array(\'a\' => int)', $result); + assertType('array{a: int}', $result); return $result; }, $results); - assertType('array<int, array(\'a\' => int)>', $type); + assertType('array<int, array{a: int}>', $type); } public function b(): void @@ -25,13 +25,13 @@ public function b(): void $results = []; $type = array_map(static function (array $result): array { - assertType('array(\'a\' => int)', $result); + assertType('array{a: int}', $result); $result['a'] = (string) $result['a']; - assertType('array(\'a\' => numeric-string)', $result); + assertType('array{a: numeric-string}', $result); return $result; }, $results); - assertType('array<int, array(\'a\' => numeric-string)>', $type); + assertType('array<int, array{a: numeric-string}>', $type); } } diff --git a/tests/PHPStan/Analyser/data/bug-4606.php b/tests/PHPStan/Analyser/data/bug-4606.php index d2d6a3ab45..1cf9cf4a32 100644 --- a/tests/PHPStan/Analyser/data/bug-4606.php +++ b/tests/PHPStan/Analyser/data/bug-4606.php @@ -11,7 +11,7 @@ */ assertType(Foo::class, $this); -assertType('array<int, array(stdClass, int)>', $assigned); +assertType('array<int, array{stdClass, int}>', $assigned); /** @@ -20,4 +20,4 @@ */ $foo = doFoo(); -assertType('array(stdClass, int)', $foo); +assertType('array{stdClass, int}', $foo); diff --git a/tests/PHPStan/Analyser/data/bug-4650.php b/tests/PHPStan/Analyser/data/bug-4650.php index c00352dc1e..f51b260c26 100644 --- a/tests/PHPStan/Analyser/data/bug-4650.php +++ b/tests/PHPStan/Analyser/data/bug-4650.php @@ -15,8 +15,8 @@ function doFoo(array $idx): void { assertType('non-empty-array<int|string>', $idx); assertNativeType('array', $idx); - assertType('array()', []); - assertNativeType('array()', []); + assertType('array{}', []); + assertNativeType('array{}', []); assertType('false', $idx === []); assertNativeType('bool', $idx === []); diff --git a/tests/PHPStan/Analyser/data/bug-4700.php b/tests/PHPStan/Analyser/data/bug-4700.php index bf73f23a09..e50cce6f7c 100644 --- a/tests/PHPStan/Analyser/data/bug-4700.php +++ b/tests/PHPStan/Analyser/data/bug-4700.php @@ -19,10 +19,10 @@ function(array $array, int $count): void { if (isset($array['e'])) $a[] = $array['e']; if (count($a) >= $count) { assertType('1|2|3|4|5', count($a)); - assertType('array(0 => mixed~null, ?1 => mixed~null, ?2 => mixed~null, ?3 => mixed~null, ?4 => mixed~null)', $a); + assertType('array{0: mixed~null, 1?: mixed~null, 2?: mixed~null, 3?: mixed~null, 4?: mixed~null}', $a); } else { assertType('0|1|2|3|4|5', count($a)); - assertType('array()|array(0 => mixed~null, ?1 => mixed~null, ?2 => mixed~null, ?3 => mixed~null, ?4 => mixed~null)', $a); + assertType('array{}|array{0: mixed~null, 1?: mixed~null, 2?: mixed~null, 3?: mixed~null, 4?: mixed~null}', $a); } }; @@ -41,9 +41,9 @@ function(array $array, int $count): void { if (isset($array['e'])) $a[] = $array['e']; if (count($a) > $count) { assertType('2|3|4|5', count($a)); - assertType('array(0 => mixed~null, ?1 => mixed~null, ?2 => mixed~null, ?3 => mixed~null, ?4 => mixed~null)', $a); + assertType('array{0: mixed~null, 1?: mixed~null, 2?: mixed~null, 3?: mixed~null, 4?: mixed~null}', $a); } else { assertType('0|1|2|3|4|5', count($a)); - assertType('array()|array(0 => mixed~null, ?1 => mixed~null, ?2 => mixed~null, ?3 => mixed~null, ?4 => mixed~null)', $a); + assertType('array{}|array{0: mixed~null, 1?: mixed~null, 2?: mixed~null, 3?: mixed~null, 4?: mixed~null}', $a); } }; diff --git a/tests/PHPStan/Analyser/data/bug-4814.php b/tests/PHPStan/Analyser/data/bug-4814.php index 4e8607a793..2fcaf231f4 100644 --- a/tests/PHPStan/Analyser/data/bug-4814.php +++ b/tests/PHPStan/Analyser/data/bug-4814.php @@ -33,7 +33,7 @@ public function doFoo() $decodedResponseBody = json_decode($body, true, 512, JSON_THROW_ON_ERROR); } catch (\Throwable $exception) { assertType('string|null', $body); - assertType('array()', $decodedResponseBody); + assertType('array{}', $decodedResponseBody); } } diff --git a/tests/PHPStan/Analyser/data/bug-5017.php b/tests/PHPStan/Analyser/data/bug-5017.php index bb7decee09..fa1abc5b46 100644 --- a/tests/PHPStan/Analyser/data/bug-5017.php +++ b/tests/PHPStan/Analyser/data/bug-5017.php @@ -35,7 +35,7 @@ public function doBar($items) public function doBar2() { $items = [0, 1, 2, 3, 4]; - assertType('array(0, 1, 2, 3, 4)', $items); + assertType('array{0, 1, 2, 3, 4}', $items); $batch = array_splice($items, 0, 2); assertType('array<0|1|2|3|4, 0|1|2|3|4>', $items); assertType('array<0|1|2|3|4, 0|1|2|3|4>', $batch); diff --git a/tests/PHPStan/Analyser/data/bug-5219.php b/tests/PHPStan/Analyser/data/bug-5219.php index 698c122090..cf7e4c0485 100644 --- a/tests/PHPStan/Analyser/data/bug-5219.php +++ b/tests/PHPStan/Analyser/data/bug-5219.php @@ -20,6 +20,6 @@ protected function bar(string $message): void $header = sprintf('%s-%s', '', ''); assertType('\'-\'', $header); - assertType('array(\'-\' => string)', [$header => $message]); + assertType('array{-: string}', [$header => $message]); } } diff --git a/tests/PHPStan/Analyser/data/bug-5584.php b/tests/PHPStan/Analyser/data/bug-5584.php index 76632898e7..45e6efeaa3 100644 --- a/tests/PHPStan/Analyser/data/bug-5584.php +++ b/tests/PHPStan/Analyser/data/bug-5584.php @@ -19,6 +19,6 @@ public function unionSum(): void $b = ['b' => 6]; } - assertType("array()|array(?'b' => 6, ?'a' => 5)", $a + $b); + assertType('array{}|array{b?: 6, a?: 5}', $a + $b); } } diff --git a/tests/PHPStan/Analyser/data/bug-empty-array.php b/tests/PHPStan/Analyser/data/bug-empty-array.php index c50df67513..91a6b8bb00 100644 --- a/tests/PHPStan/Analyser/data/bug-empty-array.php +++ b/tests/PHPStan/Analyser/data/bug-empty-array.php @@ -14,9 +14,9 @@ public function doFoo(): void { assertType('array<string>', $this->comments); $this->comments = []; - assertType('array()', $this->comments); + assertType('array{}', $this->comments); if ($this->comments === []) { - assertType('array()', $this->comments); + assertType('array{}', $this->comments); return; } else { assertType('*NEVER*', $this->comments); @@ -29,9 +29,9 @@ public function doBar(): void { assertType('array<string>', $this->comments); $this->comments = []; - assertType('array()', $this->comments); + assertType('array{}', $this->comments); if ([] === $this->comments) { - assertType('array()', $this->comments); + assertType('array{}', $this->comments); return; } else { assertType('*NEVER*', $this->comments); diff --git a/tests/PHPStan/Analyser/data/bug-pr-339.php b/tests/PHPStan/Analyser/data/bug-pr-339.php index 01e3822e96..768efbc147 100644 --- a/tests/PHPStan/Analyser/data/bug-pr-339.php +++ b/tests/PHPStan/Analyser/data/bug-pr-339.php @@ -17,17 +17,17 @@ assertType('mixed', $a); assertType('mixed', $c); if ($a) { - assertType("mixed~0|0.0|''|'0'|array()|false|null", $a); + assertType("mixed~0|0.0|''|'0'|array{}|false|null", $a); assertType('mixed', $c); assertVariableCertainty(TrinaryLogic::createYes(), $a); } if ($c) { assertType('mixed', $a); - assertType("mixed~0|0.0|''|'0'|array()|false|null", $c); + assertType("mixed~0|0.0|''|'0'|array{}|false|null", $c); assertVariableCertainty(TrinaryLogic::createYes(), $c); } } else { - assertType("0|0.0|''|'0'|array()|false|null", $a); - assertType("0|0.0|''|'0'|array()|false|null", $c); + assertType("0|0.0|''|'0'|array{}|false|null", $a); + assertType("0|0.0|''|'0'|array{}|false|null", $c); } diff --git a/tests/PHPStan/Analyser/data/closure-return-type.php b/tests/PHPStan/Analyser/data/closure-return-type.php index c06880defa..f71b056a55 100644 --- a/tests/PHPStan/Analyser/data/closure-return-type.php +++ b/tests/PHPStan/Analyser/data/closure-return-type.php @@ -27,7 +27,7 @@ public function doFoo(int $i): void $f = function (): array { return ['foo' => 'bar']; }; - assertType('array(\'foo\' => \'bar\')', $f()); + assertType('array{foo: \'bar\'}', $f()); $f = function (string $s) { return $s; diff --git a/tests/PHPStan/Analyser/data/closure-types.php b/tests/PHPStan/Analyser/data/closure-types.php index a0f60a0680..72adfe762a 100644 --- a/tests/PHPStan/Analyser/data/closure-types.php +++ b/tests/PHPStan/Analyser/data/closure-types.php @@ -13,14 +13,14 @@ class Foo public function doFoo(): void { $a = array_map(function (array $a): array { - assertType('array(\'foo\' => string, \'bar\' => int)', $a); + assertType('array{foo: string, bar: int}', $a); return $a; }, $this->arrayShapes); - assertType('array<int, array(\'foo\' => string, \'bar\' => int)>', $a); + assertType('array<int, array{foo: string, bar: int}>', $a); $b = array_map(function ($b) { - assertType('array(\'foo\' => string, \'bar\' => int)', $b); + assertType('array{foo: string, bar: int}', $b); return $b['foo']; }, $this->arrayShapes); @@ -30,8 +30,8 @@ public function doFoo(): void public function doBar(): void { usort($this->arrayShapes, function (array $a, array $b): int { - assertType('array(\'foo\' => string, \'bar\' => int)', $a); - assertType('array(\'foo\' => string, \'bar\' => int)', $b); + assertType('array{foo: string, bar: int}', $a); + assertType('array{foo: string, bar: int}', $b); return 1; }); @@ -40,8 +40,8 @@ public function doBar(): void public function doBaz(): void { usort($this->arrayShapes, function ($a, $b): int { - assertType('array(\'foo\' => string, \'bar\' => int)', $a); - assertType('array(\'foo\' => string, \'bar\' => int)', $b); + assertType('array{foo: string, bar: int}', $a); + assertType('array{foo: string, bar: int}', $b); return 1; }); diff --git a/tests/PHPStan/Analyser/data/compact.php b/tests/PHPStan/Analyser/data/compact.php index 4c29db6781..b15f2f5eb4 100644 --- a/tests/PHPStan/Analyser/data/compact.php +++ b/tests/PHPStan/Analyser/data/compact.php @@ -4,7 +4,7 @@ use function PHPStan\Testing\assertType; -assertType('array(?\'bar\' => mixed)', compact(['foo' => 'bar'])); +assertType('array{bar?: mixed}', compact(['foo' => 'bar'])); function (string $dolor): void { $foo = 'bar'; @@ -12,11 +12,11 @@ function (string $dolor): void { if (rand(0, 1)) { $lorem = 'ipsum'; } - assertType('array(\'foo\' => \'bar\', \'bar\' => \'baz\')', compact('foo', ['bar'])); - assertType('array(\'foo\' => \'bar\', \'bar\' => \'baz\', ?\'lorem\' => \'ipsum\')', compact([['foo']], 'bar', 'lorem')); + assertType('array{foo: \'bar\', bar: \'baz\'}', compact('foo', ['bar'])); + assertType('array{foo: \'bar\', bar: \'baz\', lorem?: \'ipsum\'}', compact([['foo']], 'bar', 'lorem')); assertType('array<string, mixed>', compact($dolor)); assertType('array<string, mixed>', compact([$dolor])); - assertType('array()', compact([])); + assertType('array{}', compact([])); }; diff --git a/tests/PHPStan/Analyser/data/conditional-non-empty-array.php b/tests/PHPStan/Analyser/data/conditional-non-empty-array.php index 75afc82e17..7f3ede3f30 100644 --- a/tests/PHPStan/Analyser/data/conditional-non-empty-array.php +++ b/tests/PHPStan/Analyser/data/conditional-non-empty-array.php @@ -22,7 +22,7 @@ public function doFoo(array $a): void assertType('non-empty-array', $a); assertVariableCertainty(TrinaryLogic::createYes(), $foo); } else { - assertType('array()', $a); + assertType('array{}', $a); assertVariableCertainty(TrinaryLogic::createNo(), $foo); } } diff --git a/tests/PHPStan/Analyser/data/empty-array-shape.php b/tests/PHPStan/Analyser/data/empty-array-shape.php index 4a19bf0f59..35d3dcece9 100644 --- a/tests/PHPStan/Analyser/data/empty-array-shape.php +++ b/tests/PHPStan/Analyser/data/empty-array-shape.php @@ -10,7 +10,7 @@ class Foo /** @param array{} $array */ public function doFoo(array $array): void { - assertType('array()', $array); + assertType('array{}', $array); } } diff --git a/tests/PHPStan/Analyser/data/generics.php b/tests/PHPStan/Analyser/data/generics.php index 6de2d75b6f..b203267334 100644 --- a/tests/PHPStan/Analyser/data/generics.php +++ b/tests/PHPStan/Analyser/data/generics.php @@ -96,8 +96,8 @@ function testD($int, $float, $intFloat) assertType('float|int', d($int, $float)); assertType('DateTime|int', d($int, new \DateTime())); assertType('DateTime|float|int', d($intFloat, new \DateTime())); - assertType('array()|DateTime', d([], new \DateTime())); - assertType('array(\'blabla\' => string)|DateTime', d(['blabla' => 'barrrr'], new \DateTime())); + assertType('array{}|DateTime', d([], new \DateTime())); + assertType('array{blabla: string}|DateTime', d(['blabla' => 'barrrr'], new \DateTime())); } /** @@ -763,7 +763,7 @@ function testClasses() $factory = new Factory(new \DateTime(), new A(1)); assertType( - 'array(DateTime, PHPStan\Generics\FunctionsAssertType\A<int>, string, PHPStan\Generics\FunctionsAssertType\A<DateTime>)', + 'array{DateTime, PHPStan\\Generics\\FunctionsAssertType\\A<int>, string, PHPStan\\Generics\\FunctionsAssertType\\A<DateTime>}', $factory->create(new \DateTime(), '', new A(new \DateTime())) ); } @@ -1403,7 +1403,7 @@ function (\Throwable $e): void { function (): void { $array = ['a' => 1, 'b' => 2]; - assertType('array(\'a\' => int, \'b\' => int)', a($array)); + assertType('array{a: int, b: int}', a($array)); }; @@ -1539,11 +1539,11 @@ function arrayBound5(array $a): array } function (): void { - assertType('array(1 => true)', arrayBound1([1 => true])); - assertType("array('a', 'b', 'c')", arrayBound2(range('a', 'c'))); + assertType('array{1: true}', arrayBound1([1 => true])); + assertType('array{\'a\', \'b\', \'c\'}', arrayBound2(range('a', 'c'))); assertType('array<string>', arrayBound2([1, 2, 3])); - assertType('array(true, false, true)', arrayBound3([true, false, true])); - assertType("array(array('a' => 'a'), array('b' => 'b'), array('c' => 'c'))", arrayBound4([['a' => 'a'], ['b' => 'b'], ['c' => 'c']])); + assertType('array{true, false, true}', arrayBound3([true, false, true])); + assertType('array{array{a: \'a\'}, array{b: \'b\'}, array{c: \'c\'}}', arrayBound4([['a' => 'a'], ['b' => 'b'], ['c' => 'c']])); assertType('array<string>', arrayBound5(range('a', 'c'))); }; @@ -1558,5 +1558,5 @@ function constantArrayBound(array $a): array } function (): void { - assertType("array('string', true)", constantArrayBound(['string', true])); + assertType('array{\'string\', true}', constantArrayBound(['string', true])); }; diff --git a/tests/PHPStan/Analyser/data/minmax-arrays.php b/tests/PHPStan/Analyser/data/minmax-arrays.php index 0f9ca3aede..cffe5de439 100644 --- a/tests/PHPStan/Analyser/data/minmax-arrays.php +++ b/tests/PHPStan/Analyser/data/minmax-arrays.php @@ -101,22 +101,22 @@ function dummy3(array $ints): void function dummy4(\DateTimeInterface $dateA, ?\DateTimeInterface $dateB): void { - assertType('array(0 => DateTimeInterface, ?1 => DateTimeInterface)', array_filter([$dateA, $dateB])); + assertType('array{0: DateTimeInterface, 1?: DateTimeInterface}', array_filter([$dateA, $dateB])); assertType('DateTimeInterface', min(array_filter([$dateA, $dateB]))); assertType('DateTimeInterface', max(array_filter([$dateA, $dateB]))); - assertType('array(?0 => DateTimeInterface)', array_filter([$dateB])); + assertType('array{0?: DateTimeInterface}', array_filter([$dateB])); assertType('DateTimeInterface|false', min(array_filter([$dateB]))); assertType('DateTimeInterface|false', max(array_filter([$dateB]))); } function dummy5(int $i, int $j): void { - assertType('array(?0 => int<min, -1>|int<1, max>, ?1 => int<min, -1>|int<1, max>)', array_filter([$i, $j])); - assertType('array(1 => true)', array_filter([false, true])); + assertType('array{0?: int<min, -1>|int<1, max>, 1?: int<min, -1>|int<1, max>}', array_filter([$i, $j])); + assertType('array{1: true}', array_filter([false, true])); } function dummy6(string $s, string $t): void { - assertType('array(?0 => non-empty-string, ?1 => non-empty-string)', array_filter([$s, $t])); + assertType('array{0?: non-empty-string, 1?: non-empty-string}', array_filter([$s, $t])); } class HelloWorld diff --git a/tests/PHPStan/Analyser/data/missing-closure-native-return-typehint.php b/tests/PHPStan/Analyser/data/missing-closure-native-return-typehint.php index 43b55bae18..d516f89f23 100644 --- a/tests/PHPStan/Analyser/data/missing-closure-native-return-typehint.php +++ b/tests/PHPStan/Analyser/data/missing-closure-native-return-typehint.php @@ -43,7 +43,7 @@ public function doFoo() } })()); - \PHPStan\Testing\assertType('array(\'foo\' => \'bar\')', (function () { + \PHPStan\Testing\assertType('array{foo: \'bar\'}', (function () { $array = [ 'foo' => 'bar', ]; diff --git a/tests/PHPStan/Analyser/data/native-types.php b/tests/PHPStan/Analyser/data/native-types.php index 1327192ace..86f0ad7cd1 100644 --- a/tests/PHPStan/Analyser/data/native-types.php +++ b/tests/PHPStan/Analyser/data/native-types.php @@ -121,10 +121,10 @@ public function doCatch($foo): void */ public function doForeachArrayDestructuring(array $array) { - assertType('array<string, array(int, string)>', $array); + assertType('array<string, array{int, string}>', $array); assertNativeType('array', $array); foreach ($array as $key => [$i, $s]) { - assertType('non-empty-array<string, array(int, string)>', $array); + assertType('non-empty-array<string, array{int, string}>', $array); assertNativeType('non-empty-array', $array); assertType('string', $key); diff --git a/tests/PHPStan/Analyser/data/preg_split.php b/tests/PHPStan/Analyser/data/preg_split.php index 84a7223dc8..d7a63fe676 100644 --- a/tests/PHPStan/Analyser/data/preg_split.php +++ b/tests/PHPStan/Analyser/data/preg_split.php @@ -4,5 +4,5 @@ assertType('array<int, string>|false', preg_split('/-/', '1-2-3')); assertType('array<int, string>|false', preg_split('/-/', '1-2-3', -1, PREG_SPLIT_NO_EMPTY)); -assertType('array<int, array(string, int)>|false', preg_split('/-/', '1-2-3', -1, PREG_SPLIT_OFFSET_CAPTURE)); -assertType('array<int, array(string, int)>|false', preg_split('/-/', '1-2-3', -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE)); +assertType('array<int, array{string, int}>|false', preg_split('/-/', '1-2-3', -1, PREG_SPLIT_OFFSET_CAPTURE)); +assertType('array<int, array{string, int}>|false', preg_split('/-/', '1-2-3', -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE)); diff --git a/tests/PHPStan/Analyser/data/proc_get_status.php b/tests/PHPStan/Analyser/data/proc_get_status.php index 449b4fd0ff..54f63e8094 100644 --- a/tests/PHPStan/Analyser/data/proc_get_status.php +++ b/tests/PHPStan/Analyser/data/proc_get_status.php @@ -11,5 +11,5 @@ function ($r): void { return; } - assertType('array(\'command\' => string, \'pid\' => int, \'running\' => bool, \'signaled\' => bool, \'stopped\' => bool, \'exitcode\' => int, \'termsig\' => int, \'stopsig\' => int)', $status); + assertType('array{command: string, pid: int, running: bool, signaled: bool, stopped: bool, exitcode: int, termsig: int, stopsig: int}', $status); }; diff --git a/tests/PHPStan/Analyser/data/type-aliases.php b/tests/PHPStan/Analyser/data/type-aliases.php index 9ad1e39918..a6342387ab 100644 --- a/tests/PHPStan/Analyser/data/type-aliases.php +++ b/tests/PHPStan/Analyser/data/type-aliases.php @@ -181,7 +181,7 @@ class UsesTrait1 /** @param Test $a */ public function doBar($a) { - assertType('array(string, int)', $a); + assertType('array{string, int}', $a); assertType(Test::class, $this->doFoo()); } diff --git a/tests/PHPStan/Levels/data/acceptTypes-5.json b/tests/PHPStan/Levels/data/acceptTypes-5.json index 6810f8b1d2..a3eb3cd67a 100644 --- a/tests/PHPStan/Levels/data/acceptTypes-5.json +++ b/tests/PHPStan/Levels/data/acceptTypes-5.json @@ -140,27 +140,27 @@ "ignorable": true }, { - "message": "Parameter #1 $one of method Levels\\AcceptTypes\\ArrayShapes::doBar() expects array('foo' => callable(): mixed), array<int> given.", + "message": "Parameter #1 $one of method Levels\\AcceptTypes\\ArrayShapes::doBar() expects array{foo: callable(): mixed}, array<int> given.", "line": 579, "ignorable": true }, { - "message": "Parameter #1 $one of method Levels\\AcceptTypes\\ArrayShapes::doBar() expects array('foo' => callable(): mixed), array() given.", + "message": "Parameter #1 $one of method Levels\\AcceptTypes\\ArrayShapes::doBar() expects array{foo: callable(): mixed}, array{} given.", "line": 580, "ignorable": true }, { - "message": "Parameter #1 $one of method Levels\\AcceptTypes\\ArrayShapes::doBar() expects array('foo' => callable(): mixed), array('foo' => 1) given.", + "message": "Parameter #1 $one of method Levels\\AcceptTypes\\ArrayShapes::doBar() expects array{foo: callable(): mixed}, array{foo: 1} given.", "line": 582, "ignorable": true }, { - "message": "Parameter #1 $one of method Levels\\AcceptTypes\\ArrayShapes::doBar() expects array('foo' => callable(): mixed), array('foo' => 'nonexistent') given.", + "message": "Parameter #1 $one of method Levels\\AcceptTypes\\ArrayShapes::doBar() expects array{foo: callable(): mixed}, array{foo: 'nonexistent'} given.", "line": 584, "ignorable": true }, { - "message": "Parameter #1 $one of method Levels\\AcceptTypes\\ArrayShapes::doBar() expects array('foo' => callable(): mixed), array('bar' => 'date') given.", + "message": "Parameter #1 $one of method Levels\\AcceptTypes\\ArrayShapes::doBar() expects array{foo: callable(): mixed}, array{bar: 'date'} given.", "line": 585, "ignorable": true }, @@ -190,7 +190,7 @@ "ignorable": true }, { - "message": "Parameter #1 $nonEmpty of method Levels\\AcceptTypes\\AcceptNonEmpty::doBar() expects non-empty-array, array() given.", + "message": "Parameter #1 $nonEmpty of method Levels\\AcceptTypes\\AcceptNonEmpty::doBar() expects non-empty-array, array{} given.", "line": 733, "ignorable": true }, @@ -204,4 +204,4 @@ "line": 763, "ignorable": true } -] +] \ No newline at end of file diff --git a/tests/PHPStan/Levels/data/acceptTypes-7.json b/tests/PHPStan/Levels/data/acceptTypes-7.json index 4dd170abf9..31ce9d362b 100644 --- a/tests/PHPStan/Levels/data/acceptTypes-7.json +++ b/tests/PHPStan/Levels/data/acceptTypes-7.json @@ -100,22 +100,22 @@ "ignorable": true }, { - "message": "Parameter #1 $one of method Levels\\AcceptTypes\\ArrayShapes::doBar() expects array('foo' => callable(): mixed), array<callable(): mixed> given.", + "message": "Parameter #1 $one of method Levels\\AcceptTypes\\ArrayShapes::doBar() expects array{foo: callable(): mixed}, array<callable(): mixed> given.", "line": 577, "ignorable": true }, { - "message": "Parameter #1 $one of method Levels\\AcceptTypes\\ArrayShapes::doBar() expects array('foo' => callable(): mixed), array<string> given.", + "message": "Parameter #1 $one of method Levels\\AcceptTypes\\ArrayShapes::doBar() expects array{foo: callable(): mixed}, array<string> given.", "line": 578, "ignorable": true }, { - "message": "Parameter #1 $one of method Levels\\AcceptTypes\\ArrayShapes::doBar() expects array('foo' => callable(): mixed), array()|array('foo' => 'date') given.", + "message": "Parameter #1 $one of method Levels\\AcceptTypes\\ArrayShapes::doBar() expects array{foo: callable(): mixed}, array{}|array{foo: 'date'} given.", "line": 596, "ignorable": true }, { - "message": "Parameter #1 $one of method Levels\\AcceptTypes\\ArrayShapes::doBar() expects array('foo' => callable(): mixed), iterable<callable(): mixed> given.", + "message": "Parameter #1 $one of method Levels\\AcceptTypes\\ArrayShapes::doBar() expects array{foo: callable(): mixed}, iterable<callable(): mixed> given.", "line": 597, "ignorable": true }, diff --git a/tests/PHPStan/Levels/data/arrayDestructuring-3.json b/tests/PHPStan/Levels/data/arrayDestructuring-3.json index 710133680d..a97c71f0f5 100644 --- a/tests/PHPStan/Levels/data/arrayDestructuring-3.json +++ b/tests/PHPStan/Levels/data/arrayDestructuring-3.json @@ -5,7 +5,7 @@ "ignorable": true }, { - "message": "Offset 3 does not exist on array('a', 'b', 'c').", + "message": "Offset 3 does not exist on array{'a', 'b', 'c'}.", "line": 30, "ignorable": true } diff --git a/tests/PHPStan/Levels/data/arrayDimFetches-3.json b/tests/PHPStan/Levels/data/arrayDimFetches-3.json index a1f09d578f..73c0481c0e 100644 --- a/tests/PHPStan/Levels/data/arrayDimFetches-3.json +++ b/tests/PHPStan/Levels/data/arrayDimFetches-3.json @@ -1,7 +1,7 @@ [ { - "message": "Offset 'b' does not exist on array('a' => 1).", + "message": "Offset 'b' does not exist on array{a: 1}.", "line": 21, "ignorable": true } -] +] \ No newline at end of file diff --git a/tests/PHPStan/Levels/data/arrayDimFetches-7.json b/tests/PHPStan/Levels/data/arrayDimFetches-7.json index 15e551e874..25e275b28e 100644 --- a/tests/PHPStan/Levels/data/arrayDimFetches-7.json +++ b/tests/PHPStan/Levels/data/arrayDimFetches-7.json @@ -5,17 +5,17 @@ "ignorable": true }, { - "message": "Cannot access offset 'a' on array('a' => 1)|stdClass.", + "message": "Cannot access offset 'a' on array{a: 1}|stdClass.", "line": 27, "ignorable": true }, { - "message": "Cannot access offset 'b' on array('a' => 1)|stdClass.", + "message": "Cannot access offset 'b' on array{a: 1}|stdClass.", "line": 28, "ignorable": true }, { - "message": "Offset 'b' does not exist on array('a' => 1, ?'b' => 1).", + "message": "Offset 'b' does not exist on array{a: 1, b?: 1}.", "line": 40, "ignorable": true }, @@ -29,4 +29,4 @@ "line": 58, "ignorable": true } -] +] \ No newline at end of file diff --git a/tests/PHPStan/Levels/data/stubs-methods-4.json b/tests/PHPStan/Levels/data/stubs-methods-4.json index ab8a491ae3..eb0d8a3325 100644 --- a/tests/PHPStan/Levels/data/stubs-methods-4.json +++ b/tests/PHPStan/Levels/data/stubs-methods-4.json @@ -1,36 +1,36 @@ [ { - "message": "Strict comparison using === between int and array() will always evaluate to false.", + "message": "Strict comparison using === between int and array{} will always evaluate to false.", "line": 47, "ignorable": true }, { - "message": "Strict comparison using === between int and array() will always evaluate to false.", + "message": "Strict comparison using === between int and array{} will always evaluate to false.", "line": 58, "ignorable": true }, { - "message": "Strict comparison using === between int and array() will always evaluate to false.", + "message": "Strict comparison using === between int and array{} will always evaluate to false.", "line": 89, "ignorable": true }, { - "message": "Strict comparison using === between int and array() will always evaluate to false.", + "message": "Strict comparison using === between int and array{} will always evaluate to false.", "line": 108, "ignorable": true }, { - "message": "Strict comparison using === between int and array() will always evaluate to false.", + "message": "Strict comparison using === between int and array{} will always evaluate to false.", "line": 144, "ignorable": true }, { - "message": "Strict comparison using === between int and array() will always evaluate to false.", + "message": "Strict comparison using === between int and array{} will always evaluate to false.", "line": 158, "ignorable": true }, { - "message": "Strict comparison using === between int and array() will always evaluate to false.", + "message": "Strict comparison using === between int and array{} will always evaluate to false.", "line": 175, "ignorable": true } diff --git a/tests/PHPStan/PhpDoc/TypeDescriptionTest.php b/tests/PHPStan/PhpDoc/TypeDescriptionTest.php index f62b8b624a..7ecaba543d 100644 --- a/tests/PHPStan/PhpDoc/TypeDescriptionTest.php +++ b/tests/PHPStan/PhpDoc/TypeDescriptionTest.php @@ -9,6 +9,8 @@ use PHPStan\Type\Accessory\NonEmptyArrayType; use PHPStan\Type\ArrayType; use PHPStan\Type\ClassStringType; +use PHPStan\Type\Constant\ConstantArrayTypeBuilder; +use PHPStan\Type\Constant\ConstantStringType; use PHPStan\Type\Generic\GenericClassStringType; use PHPStan\Type\IntegerType; use PHPStan\Type\IntersectionType; @@ -33,6 +35,37 @@ public function dataTest(): iterable yield ['non-empty-array<int, string>', new IntersectionType([new ArrayType(new IntegerType(), new StringType()), new NonEmptyArrayType()])]; yield ['class-string&literal-string', new IntersectionType([new ClassStringType(), new AccessoryLiteralStringType()])]; yield ['class-string<Foo>&literal-string', new IntersectionType([new GenericClassStringType(new ObjectType('Foo')), new AccessoryLiteralStringType()])]; + + $builder = ConstantArrayTypeBuilder::createEmpty(); + $builder->setOffsetValueType(new ConstantStringType('foo'), new IntegerType()); + yield ['array{foo: int}', $builder->getArray()]; + + $builder = ConstantArrayTypeBuilder::createEmpty(); + $builder->setOffsetValueType(new ConstantStringType('foo'), new IntegerType(), true); + yield ['array{foo?: int}', $builder->getArray()]; + + $builder = ConstantArrayTypeBuilder::createEmpty(); + $builder->setOffsetValueType(new ConstantStringType('foo'), new IntegerType(), true); + $builder->setOffsetValueType(new ConstantStringType('bar'), new StringType()); + yield ['array{foo?: int, bar: string}', $builder->getArray()]; + + $builder = ConstantArrayTypeBuilder::createEmpty(); + $builder->setOffsetValueType(null, new IntegerType()); + $builder->setOffsetValueType(null, new StringType()); + yield ['array{int, string}', $builder->getArray()]; + + $builder = ConstantArrayTypeBuilder::createEmpty(); + $builder->setOffsetValueType(null, new IntegerType()); + $builder->setOffsetValueType(null, new StringType(), true); + yield ['array{0: int, 1?: string}', $builder->getArray()]; + + $builder = ConstantArrayTypeBuilder::createEmpty(); + $builder->setOffsetValueType(new ConstantStringType('\'foo\''), new IntegerType()); + yield ['array{"\'foo\'": int}', $builder->getArray()]; + + $builder = ConstantArrayTypeBuilder::createEmpty(); + $builder->setOffsetValueType(new ConstantStringType('"foo"'), new IntegerType()); + yield ['array{\'"foo"\': int}', $builder->getArray()]; } /** diff --git a/tests/PHPStan/Rules/Arrays/AppendedArrayItemTypeRuleTest.php b/tests/PHPStan/Rules/Arrays/AppendedArrayItemTypeRuleTest.php index d6c27680be..6413a397ad 100644 --- a/tests/PHPStan/Rules/Arrays/AppendedArrayItemTypeRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/AppendedArrayItemTypeRuleTest.php @@ -29,15 +29,15 @@ public function testAppendedArrayItemType(): void 18, ], [ - 'Array (array<callable(): mixed>) does not accept array(1, 2, 3).', + 'Array (array<callable(): mixed>) does not accept array{1, 2, 3}.', 20, ], [ - 'Array (array<callable(): mixed>) does not accept array(\'AppendedArrayItem\\\\Foo\', \'classMethod\').', + 'Array (array<callable(): mixed>) does not accept array{\'AppendedArrayItem\\\\Foo\', \'classMethod\'}.', 23, ], [ - 'Array (array<callable(): mixed>) does not accept array(\'Foo\', \'Hello world\').', + 'Array (array<callable(): mixed>) does not accept array{\'Foo\', \'Hello world\'}.', 25, ], [ diff --git a/tests/PHPStan/Rules/Arrays/ArrayDestructuringRuleTest.php b/tests/PHPStan/Rules/Arrays/ArrayDestructuringRuleTest.php index e40f6d605e..4707547ea1 100644 --- a/tests/PHPStan/Rules/Arrays/ArrayDestructuringRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/ArrayDestructuringRuleTest.php @@ -30,7 +30,7 @@ public function testRule(): void 11, ], [ - 'Offset 0 does not exist on array().', + 'Offset 0 does not exist on array{}.', 12, ], [ @@ -38,11 +38,11 @@ public function testRule(): void 13, ], [ - 'Offset 2 does not exist on array(1, 2).', + 'Offset 2 does not exist on array{1, 2}.', 15, ], [ - 'Offset \'a\' does not exist on array(\'b\' => 1).', + 'Offset \'a\' does not exist on array{b: 1}.', 22, ], ]); diff --git a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php index d473d9cc8b..62ec8af52c 100644 --- a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php @@ -28,15 +28,15 @@ public function testRule(): void { $this->analyse([__DIR__ . '/data/nonexistent-offset.php'], [ [ - 'Offset \'b\' does not exist on array(\'a\' => stdClass, 0 => 2).', + 'Offset \'b\' does not exist on array{a: stdClass, 0: 2}.', 17, ], [ - 'Offset 1 does not exist on array(\'a\' => stdClass, 0 => 2).', + 'Offset 1 does not exist on array{a: stdClass, 0: 2}.', 18, ], [ - 'Offset \'a\' does not exist on array(\'b\' => 1).', + 'Offset \'a\' does not exist on array{b: 1}.', 55, ], [ @@ -82,23 +82,23 @@ public function testRule(): void 145, ], [ - 'Offset \'c\' does not exist on array(\'c\' => bool)|array(\'e\' => true).', + 'Offset \'c\' does not exist on array{c: bool}|array{e: true}.', 171, ], [ - 'Offset int does not exist on array()|array(1 => 1, 2 => 2)|array(3 => 3, 4 => 4).', + 'Offset int does not exist on array{}|array{1: 1, 2: 2}|array{3: 3, 4: 4}.', 190, ], [ - 'Offset int does not exist on array()|array(1 => 1, 2 => 2)|array(3 => 3, 4 => 4).', + 'Offset int does not exist on array{}|array{1: 1, 2: 2}|array{3: 3, 4: 4}.', 193, ], [ - 'Offset \'b\' does not exist on array(\'a\' => \'blabla\').', + 'Offset \'b\' does not exist on array{a: \'blabla\'}.', 225, ], [ - 'Offset \'b\' does not exist on array(\'a\' => \'blabla\').', + 'Offset \'b\' does not exist on array{a: \'blabla\'}.', 228, ], [ @@ -110,7 +110,7 @@ public function testRule(): void 253, ], [ - 'Cannot access offset \'a\' on array(\'a\' => 1, \'b\' => 1)|(Closure(): void).', + 'Cannot access offset \'a\' on array{a: 1, b: 1}|(Closure(): void).', 258, ], [ @@ -126,7 +126,7 @@ public function testRule(): void 312, ], [ - 'Offset \'baz\' does not exist on array(\'bar\' => 1, ?\'baz\' => 2).', + 'Offset \'baz\' does not exist on array{bar: 1, baz?: 2}.', 344, ], [ @@ -190,7 +190,7 @@ public function testAssignOp(): void { $this->analyse([__DIR__ . '/data/offset-access-assignop.php'], [ [ - 'Offset \'foo\' does not exist on array().', + 'Offset \'foo\' does not exist on array{}.', 4, ], [ @@ -340,7 +340,7 @@ public function testRuleWithNullsafeVariant(): void $this->analyse([__DIR__ . '/data/nonexistent-offset-nullsafe.php'], [ [ - 'Offset 1 does not exist on array(\'a\' => int).', + 'Offset 1 does not exist on array{a: int}.', 18, ], ]); diff --git a/tests/PHPStan/Rules/Arrays/OffsetAccessAssignmentRuleTest.php b/tests/PHPStan/Rules/Arrays/OffsetAccessAssignmentRuleTest.php index 665b9ec8fa..9faef229f4 100644 --- a/tests/PHPStan/Rules/Arrays/OffsetAccessAssignmentRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/OffsetAccessAssignmentRuleTest.php @@ -58,7 +58,7 @@ public function testOffsetAccessAssignmentToScalar(): void 68, ], [ - 'Cannot assign offset array(1, 2, 3) to SplObjectStorage<object, mixed>.', + 'Cannot assign offset array{1, 2, 3} to SplObjectStorage<object, mixed>.', 72, ], [ @@ -100,7 +100,7 @@ public function testOffsetAccessAssignmentToScalarWithoutMaybes(): void 68, ], [ - 'Cannot assign offset array(1, 2, 3) to SplObjectStorage<object, mixed>.', + 'Cannot assign offset array{1, 2, 3} to SplObjectStorage<object, mixed>.', 72, ], [ diff --git a/tests/PHPStan/Rules/Cast/EchoRuleTest.php b/tests/PHPStan/Rules/Cast/EchoRuleTest.php index b4d5bf6b54..29f4b7b7b3 100644 --- a/tests/PHPStan/Rules/Cast/EchoRuleTest.php +++ b/tests/PHPStan/Rules/Cast/EchoRuleTest.php @@ -23,7 +23,7 @@ public function testEchoRule(): void { $this->analyse([__DIR__ . '/data/echo.php'], [ [ - 'Parameter #1 (array()) of echo cannot be converted to string.', + 'Parameter #1 (array{}) of echo cannot be converted to string.', 7, ], [ @@ -31,7 +31,7 @@ public function testEchoRule(): void 9, ], [ - 'Parameter #1 (array()) of echo cannot be converted to string.', + 'Parameter #1 (array{}) of echo cannot be converted to string.', 11, ], [ @@ -43,7 +43,7 @@ public function testEchoRule(): void 13, ], [ - 'Parameter #1 (\'string\'|array(\'string\')) of echo cannot be converted to string.', + 'Parameter #1 (\'string\'|array{\'string\'}) of echo cannot be converted to string.', 17, ], ]); diff --git a/tests/PHPStan/Rules/Cast/PrintRuleTest.php b/tests/PHPStan/Rules/Cast/PrintRuleTest.php index dc5e0429cf..878286f45f 100644 --- a/tests/PHPStan/Rules/Cast/PrintRuleTest.php +++ b/tests/PHPStan/Rules/Cast/PrintRuleTest.php @@ -23,7 +23,7 @@ public function testPrintRule(): void { $this->analyse([__DIR__ . '/data/print.php'], [ [ - 'Parameter array() of print cannot be converted to string.', + 'Parameter array{} of print cannot be converted to string.', 5, ], [ @@ -35,7 +35,7 @@ public function testPrintRule(): void 9, ], [ - 'Parameter array() of print cannot be converted to string.', + 'Parameter array{} of print cannot be converted to string.', 13, ], [ @@ -47,7 +47,7 @@ public function testPrintRule(): void 17, ], [ - 'Parameter \'string\'|array(\'string\') of print cannot be converted to string.', + 'Parameter \'string\'|array{\'string\'} of print cannot be converted to string.', 21, ], ]); diff --git a/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php b/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php index 8e7633a5df..c15decc0a7 100644 --- a/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php @@ -102,43 +102,43 @@ public function testImpossibleCheckTypeFunctionCall(): void 212, ], [ - 'Call to function in_array() with arguments int, array(\'foo\', \'bar\') and true will always evaluate to false.', + 'Call to function in_array() with arguments int, array{\'foo\', \'bar\'} and true will always evaluate to false.', 235, ], [ - 'Call to function in_array() with arguments \'bar\'|\'foo\', array(\'baz\', \'lorem\') and true will always evaluate to false.', + 'Call to function in_array() with arguments \'bar\'|\'foo\', array{\'baz\', \'lorem\'} and true will always evaluate to false.', 244, ], [ - 'Call to function in_array() with arguments \'bar\'|\'foo\', array(\'foo\', \'bar\') and true will always evaluate to true.', + 'Call to function in_array() with arguments \'bar\'|\'foo\', array{\'foo\', \'bar\'} and true will always evaluate to true.', 248, ], [ - 'Call to function in_array() with arguments \'foo\', array(\'foo\') and true will always evaluate to true.', + 'Call to function in_array() with arguments \'foo\', array{\'foo\'} and true will always evaluate to true.', 252, ], [ - 'Call to function in_array() with arguments \'foo\', array(\'foo\', \'bar\') and true will always evaluate to true.', + 'Call to function in_array() with arguments \'foo\', array{\'foo\', \'bar\'} and true will always evaluate to true.', 256, ], [ - 'Call to function in_array() with arguments \'bar\', array()|array(\'foo\') and true will always evaluate to false.', + 'Call to function in_array() with arguments \'bar\', array{}|array{\'foo\'} and true will always evaluate to false.', 320, ], [ - 'Call to function in_array() with arguments \'baz\', array(0 => \'bar\', ?1 => \'foo\') and true will always evaluate to false.', + 'Call to function in_array() with arguments \'baz\', array{0: \'bar\', 1?: \'foo\'} and true will always evaluate to false.', 336, ], [ - 'Call to function in_array() with arguments \'foo\', array() and true will always evaluate to false.', + 'Call to function in_array() with arguments \'foo\', array{} and true will always evaluate to false.', 343, ], [ - 'Call to function array_key_exists() with \'a\' and array(\'a\' => 1, ?\'b\' => 2) will always evaluate to true.', + 'Call to function array_key_exists() with \'a\' and array{a: 1, b?: 2} will always evaluate to true.', 360, ], [ - 'Call to function array_key_exists() with \'c\' and array(\'a\' => 1, ?\'b\' => 2) will always evaluate to false.', + 'Call to function array_key_exists() with \'c\' and array{a: 1, b?: 2} will always evaluate to false.', 366, ], [ @@ -279,27 +279,27 @@ public function testImpossibleCheckTypeFunctionCallWithoutAlwaysTrue(): void 212, ], [ - 'Call to function in_array() with arguments int, array(\'foo\', \'bar\') and true will always evaluate to false.', + 'Call to function in_array() with arguments int, array{\'foo\', \'bar\'} and true will always evaluate to false.', 235, ], [ - 'Call to function in_array() with arguments \'bar\'|\'foo\', array(\'baz\', \'lorem\') and true will always evaluate to false.', + 'Call to function in_array() with arguments \'bar\'|\'foo\', array{\'baz\', \'lorem\'} and true will always evaluate to false.', 244, ], [ - 'Call to function in_array() with arguments \'bar\', array()|array(\'foo\') and true will always evaluate to false.', + 'Call to function in_array() with arguments \'bar\', array{}|array{\'foo\'} and true will always evaluate to false.', 320, ], [ - 'Call to function in_array() with arguments \'baz\', array(0 => \'bar\', ?1 => \'foo\') and true will always evaluate to false.', + 'Call to function in_array() with arguments \'baz\', array{0: \'bar\', 1?: \'foo\'} and true will always evaluate to false.', 336, ], [ - 'Call to function in_array() with arguments \'foo\', array() and true will always evaluate to false.', + 'Call to function in_array() with arguments \'foo\', array{} and true will always evaluate to false.', 343, ], [ - 'Call to function array_key_exists() with \'c\' and array(\'a\' => 1, ?\'b\' => 2) will always evaluate to false.', + 'Call to function array_key_exists() with \'c\' and array{a: 1, b?: 2} will always evaluate to false.', 366, ], [ diff --git a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php index a572b8c6a1..b92346d98f 100644 --- a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php @@ -111,11 +111,11 @@ public function testStrictComparison(): void 284, ], [ - 'Strict comparison using === between array(\'X\' => 1) and array(\'X\' => 2) will always evaluate to false.', + 'Strict comparison using === between array{X: 1} and array{X: 2} will always evaluate to false.', 292, ], [ - 'Strict comparison using === between array(\'X\' => 1, \'Y\' => 2) and array(\'X\' => 2, \'Y\' => 1) will always evaluate to false.', + 'Strict comparison using === between array{X: 1, Y: 2} and array{X: 2, Y: 1} will always evaluate to false.', 300, ], [ @@ -293,11 +293,11 @@ public function testStrictComparisonWithoutAlwaysTrue(): void 284, ], [ - 'Strict comparison using === between array(\'X\' => 1) and array(\'X\' => 2) will always evaluate to false.', + 'Strict comparison using === between array{X: 1} and array{X: 2} will always evaluate to false.', 292, ], [ - 'Strict comparison using === between array(\'X\' => 1, \'Y\' => 2) and array(\'X\' => 2, \'Y\' => 1) will always evaluate to false.', + 'Strict comparison using === between array{X: 1, Y: 2} and array{X: 2, Y: 1} will always evaluate to false.', 300, ], [ diff --git a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php index 5353534e56..59c8dfda09 100644 --- a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php @@ -55,11 +55,11 @@ public function testRule(): void 25, ], [ - 'Parameter #1 $i of callable array($this(CallCallables\Foo), \'doBar\') expects int, string given.', + 'Parameter #1 $i of callable array{$this(CallCallables\\Foo}, \'doBar\') expects int, string given.', 33, ], [ - 'Callable array(\'CallCallables\\\\Foo\', \'doStaticBaz\') invoked with 1 parameter, 0 required.', + 'Callable array{\'CallCallables\\\\Foo\', \'doStaticBaz\'} invoked with 1 parameter, 0 required.', 39, ], [ @@ -108,7 +108,7 @@ public function testRule(): void 113, ], [ - 'Trying to invoke array(object, \'bar\') but it might not be a callable.', + 'Trying to invoke array{object, \'bar\'} but it might not be a callable.', 131, ], [ @@ -124,15 +124,15 @@ public function testRule(): void 148, ], [ - 'Trying to invoke array(object, \'yo\') but it might not be a callable.', + 'Trying to invoke array{object, \'yo\'} but it might not be a callable.', 163, ], [ - 'Trying to invoke array(object, \'yo\') but it might not be a callable.', + 'Trying to invoke array{object, \'yo\'} but it might not be a callable.', 167, ], [ - 'Trying to invoke array(\'CallCallables\\\\CallableInForeach\', \'bar\'|\'foo\') but it might not be a callable.', + 'Trying to invoke array{\'CallCallables\\\\CallableInForeach\', \'bar\'|\'foo\'} but it might not be a callable.', 179, ], ]); diff --git a/tests/PHPStan/Rules/Functions/ClosureReturnTypeRuleTest.php b/tests/PHPStan/Rules/Functions/ClosureReturnTypeRuleTest.php index addb8aaf1a..90848f210b 100644 --- a/tests/PHPStan/Rules/Functions/ClosureReturnTypeRuleTest.php +++ b/tests/PHPStan/Rules/Functions/ClosureReturnTypeRuleTest.php @@ -40,7 +40,7 @@ public function testClosureReturnTypeRule(): void 46, ], [ - 'Anonymous function should return array()|null but empty return statement found.', + 'Anonymous function should return array{}|null but empty return statement found.', 88, ], [ diff --git a/tests/PHPStan/Rules/Generators/YieldFromTypeRuleTest.php b/tests/PHPStan/Rules/Generators/YieldFromTypeRuleTest.php index 7a949cdc35..b70e2508d8 100644 --- a/tests/PHPStan/Rules/Generators/YieldFromTypeRuleTest.php +++ b/tests/PHPStan/Rules/Generators/YieldFromTypeRuleTest.php @@ -37,7 +37,7 @@ public function testRule(): void 41, ], [ - 'Generator expects value type array(DateTime, DateTime, stdClass, DateTimeImmutable), array(0 => DateTime, 1 => DateTime, 2 => stdClass, 4 => DateTimeImmutable) given.', + 'Generator expects value type array{DateTime, DateTime, stdClass, DateTimeImmutable}, array{0: DateTime, 1: DateTime, 2: stdClass, 4: DateTimeImmutable} given.', 74, ], [ diff --git a/tests/PHPStan/Rules/Generators/YieldTypeRuleTest.php b/tests/PHPStan/Rules/Generators/YieldTypeRuleTest.php index 58799d2296..c03a5b5987 100644 --- a/tests/PHPStan/Rules/Generators/YieldTypeRuleTest.php +++ b/tests/PHPStan/Rules/Generators/YieldTypeRuleTest.php @@ -45,7 +45,7 @@ public function testRule(): void 17, ], [ - 'Generator expects value type array(0 => DateTime, 1 => DateTime, 2 => stdClass, 4 => DateTimeImmutable), array(DateTime, DateTime, stdClass, DateTimeImmutable) given.', + 'Generator expects value type array{0: DateTime, 1: DateTime, 2: stdClass, 4: DateTimeImmutable}, array{DateTime, DateTime, stdClass, DateTimeImmutable} given.', 25, ], [ diff --git a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php index 630f370f5b..d03a9fbb00 100644 --- a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php @@ -390,15 +390,15 @@ public function testCallMethods(): void 914, ], [ - 'Parameter #1 $callable of method Test\MethodExists::doBar() expects callable(): mixed, array(class-string|object, \'foo\') given.', + 'Parameter #1 $callable of method Test\\MethodExists::doBar() expects callable(): mixed, array{class-string|object, \'foo\'} given.', 915, ], [ - 'Parameter #1 $callable of method Test\MethodExists::doBar() expects callable(): mixed, array(class-string|object, \'bar\') given.', + 'Parameter #1 $callable of method Test\\MethodExists::doBar() expects callable(): mixed, array{class-string|object, \'bar\'} given.', 916, ], [ - 'Parameter #1 $callable of method Test\MethodExists::doBar() expects callable(): mixed, array(object, \'bar\') given.', + 'Parameter #1 $callable of method Test\\MethodExists::doBar() expects callable(): mixed, array{object, \'bar\'} given.', 921, ], [ @@ -475,11 +475,11 @@ public function testCallMethods(): void 'See: https://phpstan.org/blog/solving-phpstan-error-unable-to-resolve-template-type', ], [ - 'Parameter #1 $a of method Test\CallableWithMixedArray::doBar() expects callable(array<string>): array<string>, Closure(array): array(\'foo\')|null given.', + 'Parameter #1 $a of method Test\\CallableWithMixedArray::doBar() expects callable(array<string>): array<string>, Closure(array): array{\'foo\'}|null given.', 1533, ], [ - 'Parameter #1 $members of method Test\ParameterTypeCheckVerbosity::doBar() expects array<array(\'id\' => string, \'code\' => string)>, array<array(\'code\' => string)> given.', + 'Parameter #1 $members of method Test\\ParameterTypeCheckVerbosity::doBar() expects array<array{id: string, code: string}>, array<array{code: string}> given.', 1589, ], [ @@ -701,15 +701,15 @@ public function testCallMethodsOnThisOnly(): void 867, ], [ - 'Parameter #1 $callable of method Test\MethodExists::doBar() expects callable(): mixed, array(class-string|object, \'foo\') given.', + 'Parameter #1 $callable of method Test\\MethodExists::doBar() expects callable(): mixed, array{class-string|object, \'foo\'} given.', 915, ], [ - 'Parameter #1 $callable of method Test\MethodExists::doBar() expects callable(): mixed, array(class-string|object, \'bar\') given.', + 'Parameter #1 $callable of method Test\\MethodExists::doBar() expects callable(): mixed, array{class-string|object, \'bar\'} given.', 916, ], [ - 'Parameter #1 $callable of method Test\MethodExists::doBar() expects callable(): mixed, array(object, \'bar\') given.', + 'Parameter #1 $callable of method Test\\MethodExists::doBar() expects callable(): mixed, array{object, \'bar\'} given.', 921, ], [ @@ -762,11 +762,11 @@ public function testCallMethodsOnThisOnly(): void 'See: https://phpstan.org/blog/solving-phpstan-error-unable-to-resolve-template-type', ], [ - 'Parameter #1 $a of method Test\CallableWithMixedArray::doBar() expects callable(array<string>): array<string>, Closure(array): array(\'foo\')|null given.', + 'Parameter #1 $a of method Test\\CallableWithMixedArray::doBar() expects callable(array<string>): array<string>, Closure(array): array{\'foo\'}|null given.', 1533, ], [ - 'Parameter #1 $members of method Test\ParameterTypeCheckVerbosity::doBar() expects array<array(\'id\' => string, \'code\' => string)>, array<array(\'code\' => string)> given.', + 'Parameter #1 $members of method Test\\ParameterTypeCheckVerbosity::doBar() expects array<array{id: string, code: string}>, array<array{code: string}> given.', 1589, ], [ diff --git a/tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php b/tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php index b667ebcd78..9366509dcb 100644 --- a/tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php @@ -433,7 +433,7 @@ public function testBug1971(): void $this->checkThisOnly = false; $this->analyse([__DIR__ . '/data/bug-1971.php'], [ [ - 'Parameter #1 $callback of static method Closure::fromCallable() expects callable(): mixed, array(class-string<static(Bug1971\HelloWorld)>, \'sayHello2\') given.', + 'Parameter #1 $callback of static method Closure::fromCallable() expects callable(): mixed, array{class-string<static(Bug1971\\HelloWorld)>, \'sayHello2\'} given.', 16, ], ]); diff --git a/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php b/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php index 13fe986ae1..982a5cd157 100644 --- a/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php +++ b/tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php @@ -429,15 +429,15 @@ public function testBug4590(): void { $this->analyse([__DIR__ . '/data/bug-4590.php'], [ [ - 'Method Bug4590\Controller::test1() should return Bug4590\OkResponse<array<string, string>> but returns Bug4590\OkResponse<array(\'ok\' => string)>.', + 'Method Bug4590\\Controller::test1() should return Bug4590\\OkResponse<array<string, string>> but returns Bug4590\\OkResponse<array{ok: string}>.', 39, ], [ - 'Method Bug4590\Controller::test2() should return Bug4590\OkResponse<array<int, string>> but returns Bug4590\OkResponse<array(string)>.', + 'Method Bug4590\\Controller::test2() should return Bug4590\\OkResponse<array<int, string>> but returns Bug4590\\OkResponse<array{string}>.', 47, ], [ - 'Method Bug4590\Controller::test3() should return Bug4590\OkResponse<array<string>> but returns Bug4590\OkResponse<array(string)>.', + 'Method Bug4590\\Controller::test3() should return Bug4590\\OkResponse<array<string>> but returns Bug4590\\OkResponse<array{string}>.', 55, ], ]); diff --git a/tests/PHPStan/Rules/Operators/InvalidUnaryOperationRuleTest.php b/tests/PHPStan/Rules/Operators/InvalidUnaryOperationRuleTest.php index 77bb4fe9e3..7dd8c33e28 100644 --- a/tests/PHPStan/Rules/Operators/InvalidUnaryOperationRuleTest.php +++ b/tests/PHPStan/Rules/Operators/InvalidUnaryOperationRuleTest.php @@ -33,7 +33,7 @@ public function testRule(): void 20, ], [ - 'Unary operation "~" on array() results in an error.', + 'Unary operation "~" on array{} results in an error.', 24, ], ]); diff --git a/tests/PHPStan/Rules/Variables/EmptyRuleTest.php b/tests/PHPStan/Rules/Variables/EmptyRuleTest.php index 5a300c8cda..795efe943e 100644 --- a/tests/PHPStan/Rules/Variables/EmptyRuleTest.php +++ b/tests/PHPStan/Rules/Variables/EmptyRuleTest.php @@ -36,27 +36,27 @@ public function testRule(): void $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/empty-rule.php'], [ [ - 'Offset \'nonexistent\' on array(?0 => bool, ?1 => false, 2 => bool, 3 => false, 4 => true) in empty() does not exist.', + 'Offset \'nonexistent\' on array{0?: bool, 1?: false, 2: bool, 3: false, 4: true} in empty() does not exist.', 22, ], [ - 'Offset 3 on array(?0 => bool, ?1 => false, 2 => bool, 3 => false, 4 => true) in empty() always exists and is always falsy.', + 'Offset 3 on array{0?: bool, 1?: false, 2: bool, 3: false, 4: true} in empty() always exists and is always falsy.', 24, ], [ - 'Offset 4 on array(?0 => bool, ?1 => false, 2 => bool, 3 => false, 4 => true) in empty() always exists and is not falsy.', + 'Offset 4 on array{0?: bool, 1?: false, 2: bool, 3: false, 4: true} in empty() always exists and is not falsy.', 25, ], [ - 'Offset 0 on array(\'\', \'0\', \'foo\', \'\'|\'foo\') in empty() always exists and is always falsy.', + 'Offset 0 on array{\'\', \'0\', \'foo\', \'\'|\'foo\'} in empty() always exists and is always falsy.', 36, ], [ - 'Offset 1 on array(\'\', \'0\', \'foo\', \'\'|\'foo\') in empty() always exists and is always falsy.', + 'Offset 1 on array{\'\', \'0\', \'foo\', \'\'|\'foo\'} in empty() always exists and is always falsy.', 37, ], [ - 'Offset 2 on array(\'\', \'0\', \'foo\', \'\'|\'foo\') in empty() always exists and is not falsy.', + 'Offset 2 on array{\'\', \'0\', \'foo\', \'\'|\'foo\'} in empty() always exists and is not falsy.', 38, ], [ diff --git a/tests/PHPStan/Rules/Variables/IssetRuleTest.php b/tests/PHPStan/Rules/Variables/IssetRuleTest.php index 5ea863b812..e67fb91361 100644 --- a/tests/PHPStan/Rules/Variables/IssetRuleTest.php +++ b/tests/PHPStan/Rules/Variables/IssetRuleTest.php @@ -45,11 +45,11 @@ public function testRule(): void 41, ], [ - 'Offset \'string\' on array(1, 2, 3) in isset() does not exist.', + 'Offset \'string\' on array{1, 2, 3} in isset() does not exist.', 45, ], [ - 'Offset \'string\' on array(array(1), array(2), array(3)) in isset() does not exist.', + 'Offset \'string\' on array{array{1}, array{2}, array{3}} in isset() does not exist.', 49, ], [ @@ -57,15 +57,15 @@ public function testRule(): void 51, ], [ - 'Offset \'dim\' on array(\'dim\' => 1, \'dim-null\' => 1|null, \'dim-null-offset\' => array(\'a\' => true|null), \'dim-empty\' => array()) in isset() always exists and is not nullable.', + 'Offset \'dim\' on array{dim: 1, dim-null: 1|null, dim-null-offset: array{a: true|null}, dim-empty: array{}} in isset() always exists and is not nullable.', 67, ], [ - 'Offset \'dim-null-not-set\' on array(\'dim\' => 1, \'dim-null\' => 1|null, \'dim-null-offset\' => array(\'a\' => true|null), \'dim-empty\' => array()) in isset() does not exist.', + 'Offset \'dim-null-not-set\' on array{dim: 1, dim-null: 1|null, dim-null-offset: array{a: true|null}, dim-empty: array{}} in isset() does not exist.', 73, ], [ - 'Offset \'b\' on array() in isset() does not exist.', + 'Offset \'b\' on array{} in isset() does not exist.', 79, ], [ @@ -109,11 +109,11 @@ public function testRule(): void 124, ], [ - "Offset 'foo' on array('foo' => string) in isset() always exists and is not nullable.", + 'Offset \'foo\' on array{foo: string} in isset() always exists and is not nullable.', 170, ], [ - "Offset 'bar' on array('bar' => 1) in isset() always exists and is not nullable.", + 'Offset \'bar\' on array{bar: 1} in isset() always exists and is not nullable.', 173, ], ]); @@ -132,11 +132,11 @@ public function testRuleWithoutTreatPhpDocTypesAsCertain(): void 41, ], [ - 'Offset \'string\' on array(1, 2, 3) in isset() does not exist.', + 'Offset \'string\' on array{1, 2, 3} in isset() does not exist.', 45, ], [ - 'Offset \'string\' on array(array(1), array(2), array(3)) in isset() does not exist.', + 'Offset \'string\' on array{array{1}, array{2}, array{3}} in isset() does not exist.', 49, ], [ @@ -144,15 +144,15 @@ public function testRuleWithoutTreatPhpDocTypesAsCertain(): void 51, ], [ - 'Offset \'dim\' on array(\'dim\' => 1, \'dim-null\' => 1|null, \'dim-null-offset\' => array(\'a\' => true|null), \'dim-empty\' => array()) in isset() always exists and is not nullable.', + 'Offset \'dim\' on array{dim: 1, dim-null: 1|null, dim-null-offset: array{a: true|null}, dim-empty: array{}} in isset() always exists and is not nullable.', 67, ], [ - 'Offset \'dim-null-not-set\' on array(\'dim\' => 1, \'dim-null\' => 1|null, \'dim-null-offset\' => array(\'a\' => true|null), \'dim-empty\' => array()) in isset() does not exist.', + 'Offset \'dim-null-not-set\' on array{dim: 1, dim-null: 1|null, dim-null-offset: array{a: true|null}, dim-empty: array{}} in isset() does not exist.', 73, ], [ - 'Offset \'b\' on array() in isset() does not exist.', + 'Offset \'b\' on array{} in isset() does not exist.', 79, ], [ diff --git a/tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php b/tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php index 60778f3b38..8399fe241d 100644 --- a/tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php +++ b/tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php @@ -43,11 +43,11 @@ public function testCoalesceRule(): void 41, ], [ - 'Offset \'string\' on array(1, 2, 3) on left side of ?? does not exist.', + 'Offset \'string\' on array{1, 2, 3} on left side of ?? does not exist.', 45, ], [ - 'Offset \'string\' on array(array(1), array(2), array(3)) on left side of ?? does not exist.', + 'Offset \'string\' on array{array{1}, array{2}, array{3}} on left side of ?? does not exist.', 49, ], [ @@ -55,15 +55,15 @@ public function testCoalesceRule(): void 51, ], [ - 'Offset \'dim\' on array(\'dim\' => 1, \'dim-null\' => 1|null, \'dim-null-offset\' => array(\'a\' => true|null), \'dim-empty\' => array()) on left side of ?? always exists and is not nullable.', + 'Offset \'dim\' on array{dim: 1, dim-null: 1|null, dim-null-offset: array{a: true|null}, dim-empty: array{}} on left side of ?? always exists and is not nullable.', 67, ], [ - 'Offset \'dim-null-not-set\' on array(\'dim\' => 1, \'dim-null\' => 1|null, \'dim-null-offset\' => array(\'a\' => true|null), \'dim-empty\' => array()) on left side of ?? does not exist.', + 'Offset \'dim-null-not-set\' on array{dim: 1, dim-null: 1|null, dim-null-offset: array{a: true|null}, dim-empty: array{}} on left side of ?? does not exist.', 73, ], [ - 'Offset \'b\' on array() on left side of ?? does not exist.', + 'Offset \'b\' on array{} on left side of ?? does not exist.', 79, ], [ @@ -150,11 +150,11 @@ public function testCoalesceAssignRule(): void 41, ], [ - 'Offset \'string\' on array(1, 2, 3) on left side of ??= does not exist.', + 'Offset \'string\' on array{1, 2, 3} on left side of ??= does not exist.', 45, ], [ - 'Offset \'string\' on array(array(1), array(2), array(3)) on left side of ??= does not exist.', + 'Offset \'string\' on array{array{1}, array{2}, array{3}} on left side of ??= does not exist.', 49, ], [ @@ -162,15 +162,15 @@ public function testCoalesceAssignRule(): void 51, ], [ - 'Offset \'dim\' on array(\'dim\' => 1, \'dim-null\' => 1|null, \'dim-null-offset\' => array(\'a\' => true|null), \'dim-empty\' => array()) on left side of ??= always exists and is not nullable.', + 'Offset \'dim\' on array{dim: 1, dim-null: 1|null, dim-null-offset: array{a: true|null}, dim-empty: array{}} on left side of ??= always exists and is not nullable.', 67, ], [ - 'Offset \'dim-null-not-set\' on array(\'dim\' => 1, \'dim-null\' => 0|1, \'dim-null-offset\' => array(\'a\' => true|null), \'dim-empty\' => array()) on left side of ??= does not exist.', + 'Offset \'dim-null-not-set\' on array{dim: 1, dim-null: 0|1, dim-null-offset: array{a: true|null}, dim-empty: array{}} on left side of ??= does not exist.', 73, ], [ - 'Offset \'b\' on array() on left side of ??= does not exist.', + 'Offset \'b\' on array{} on left side of ??= does not exist.', 79, ], [ diff --git a/tests/PHPStan/Type/TypeCombinatorTest.php b/tests/PHPStan/Type/TypeCombinatorTest.php index 380dd85c72..fd6a26e093 100644 --- a/tests/PHPStan/Type/TypeCombinatorTest.php +++ b/tests/PHPStan/Type/TypeCombinatorTest.php @@ -693,7 +693,7 @@ public function dataUnion(): array ]), ], ConstantArrayType::class, - 'array(\'foo\' => DateTimeImmutable|null, \'bar\' => int|string)', + 'array{foo: DateTimeImmutable|null, bar: int|string}', ], [ [ @@ -711,7 +711,7 @@ public function dataUnion(): array ]), ], ConstantArrayType::class, - 'array(\'foo\' => DateTimeImmutable|null, ?\'bar\' => int)', + 'array{foo: DateTimeImmutable|null, bar?: int}', ], [ [ @@ -733,7 +733,7 @@ public function dataUnion(): array ]), ], ConstantArrayType::class, - 'array(\'foo\' => DateTimeImmutable|null, \'bar\' => int|string, ?\'baz\' => int)', + 'array{foo: DateTimeImmutable|null, bar: int|string, baz?: int}', ], [ [ @@ -902,7 +902,7 @@ public function dataUnion(): array ]), ], IntersectionType::class, - 'array(object, \'foo\')&callable(): mixed', + 'array{object, \'foo\'}&callable(): mixed', ], [ [ @@ -1650,7 +1650,7 @@ public function dataUnion(): array ]), ], UnionType::class, - 'array()|array(string)', + 'array{}|array{string}', ], [ [ @@ -1662,7 +1662,7 @@ public function dataUnion(): array ], 1, [0]), ], UnionType::class, - 'array()|array(?0 => string)', + 'array{}|array{0?: string}', ], [ [ @@ -1682,7 +1682,7 @@ public function dataUnion(): array ]), ], UnionType::class, - 'array(\'a\' => int, \'b\' => int)|array(\'c\' => int, \'d\' => int)', + 'array{a: int, b: int}|array{c: int, d: int}', ], [ [ @@ -1700,7 +1700,7 @@ public function dataUnion(): array ]), ], ConstantArrayType::class, - 'array(\'a\' => int, ?\'b\' => int)', + 'array{a: int, b?: int}', ], [ [ @@ -1720,7 +1720,7 @@ public function dataUnion(): array ]), ], UnionType::class, - 'array(\'a\' => int, \'b\' => int)|array(\'b\' => int, \'c\' => int)', + 'array{a: int, b: int}|array{b: int, c: int}', ], [ [ @@ -1744,7 +1744,7 @@ public function dataUnion(): array StaticTypeFactory::falsey(), ], UnionType::class, - '0|0.0|\'\'|\'0\'|array()|false|null', + '0|0.0|\'\'|\'0\'|array{}|false|null', ], [ [ @@ -1752,7 +1752,7 @@ public function dataUnion(): array StaticTypeFactory::truthy(), ], MixedType::class, - 'mixed~0|0.0|\'\'|\'0\'|array()|false|null=implicit', + 'mixed~0|0.0|\'\'|\'0\'|array{}|false|null=implicit', ], [ [ @@ -2396,7 +2396,7 @@ public function dataIntersect(): array new HasOffsetType(new ConstantStringType('a')), ], ConstantArrayType::class, - 'array(\'a\' => \'foo\')', + 'array{a: \'foo\'}', ], [ [ @@ -2432,7 +2432,7 @@ public function dataIntersect(): array new HasOffsetType(new ConstantStringType('b')), ], ConstantArrayType::class, - 'array(\'b\' => \'foo\')', + 'array{b: \'foo\'}', ], [ [ @@ -2446,7 +2446,7 @@ public function dataIntersect(): array new HasOffsetType(new ConstantStringType('a')), ], ConstantArrayType::class, - 'array(\'a\' => \'foo\')', + 'array{a: \'foo\'}', ], [ [ @@ -2523,7 +2523,7 @@ public function dataIntersect(): array new NonEmptyArrayType(), ], ConstantArrayType::class, - 'array(string)', + 'array{string}', ], [ [ @@ -2989,7 +2989,7 @@ public function dataIntersect(): array new HasOffsetType(new ConstantStringType('a')), ], ConstantArrayType::class, - 'array(\'a\' => int, \'b\' => int)', + 'array{a: int, b: int}', ], [ [ @@ -3255,13 +3255,13 @@ public function dataRemove(): array StaticTypeFactory::truthy(), StaticTypeFactory::falsey(), MixedType::class, - 'mixed~0|0.0|\'\'|\'0\'|array()|false|null', + 'mixed~0|0.0|\'\'|\'0\'|array{}|false|null', ], [ StaticTypeFactory::falsey(), StaticTypeFactory::truthy(), UnionType::class, - '0|0.0|\'\'|\'0\'|array()|false|null', + '0|0.0|\'\'|\'0\'|array{}|false|null', ], [ new BooleanType(), @@ -3389,7 +3389,7 @@ public function dataRemove(): array ), new ConstantArrayType([], []), ConstantArrayType::class, - 'array(string)', + 'array{string}', ], [ new IntersectionType([ @@ -3404,7 +3404,7 @@ public function dataRemove(): array new ArrayType(new MixedType(), new MixedType()), new NonEmptyArrayType(), ConstantArrayType::class, - 'array()', + 'array{}', ], [ new ArrayType(new MixedType(), new MixedType()), @@ -3578,7 +3578,7 @@ public function dataRemove(): array ], 2, [1]), new HasOffsetType(new ConstantIntegerType(1)), ConstantArrayType::class, - 'array(string)', + 'array{string}', ], [ new ConstantArrayType([ @@ -3648,7 +3648,7 @@ public function testSpecificUnionConstantArray(): void } $resultType = TypeCombinator::union(...$arrays); $this->assertInstanceOf(ConstantArrayType::class, $resultType); - $this->assertSame('array(0 => string, ?\'test\' => string, ?1 => string, ?2 => string, ?3 => string, ?4 => string)', $resultType->describe(VerbosityLevel::precise())); + $this->assertSame('array{0: string, test?: string, 1?: string, 2?: string, 3?: string, 4?: string}', $resultType->describe(VerbosityLevel::precise())); } } diff --git a/tests/PHPStan/Type/UnionTypeTest.php b/tests/PHPStan/Type/UnionTypeTest.php index 9ba73d7e06..44ee94356e 100644 --- a/tests/PHPStan/Type/UnionTypeTest.php +++ b/tests/PHPStan/Type/UnionTypeTest.php @@ -592,7 +592,7 @@ public function dataDescribe(): array ]), new ConstantStringType('aaa') ), - '\'aaa\'|array(\'a\' => int|string, \'b\' => bool|float)', + '\'aaa\'|array{a: int|string, b: bool|float}', 'array<string, bool|float|int|string>|string', ], [ @@ -613,7 +613,7 @@ public function dataDescribe(): array ]), new ConstantStringType('aaa') ), - '\'aaa\'|array(\'a\' => string, \'b\' => bool)|array(\'b\' => int, \'c\' => float)', + '\'aaa\'|array{a: string, b: bool}|array{b: int, c: float}', 'array<string, bool|float|int|string>|string', ], [ @@ -634,7 +634,7 @@ public function dataDescribe(): array ]), new ConstantStringType('aaa') ), - '\'aaa\'|array(\'a\' => string, \'b\' => bool)|array(\'c\' => int, \'d\' => float)', + '\'aaa\'|array{a: string, b: bool}|array{c: int, d: float}', 'array<string, bool|float|int|string>|string', ], [ @@ -654,7 +654,7 @@ public function dataDescribe(): array new FloatType(), ]) ), - 'array(0 => int|string, ?1 => bool, ?2 => float)', + 'array{0: int|string, 1?: bool, 2?: float}', 'array<int, bool|float|int|string>', ], [ @@ -666,7 +666,7 @@ public function dataDescribe(): array new ConstantStringType('barrr'), ]) ), - 'array()|array(\'foooo\' => \'barrr\')', + 'array{}|array{foooo: \'barrr\'}', 'array<string, string>', ], [ diff --git a/tests/e2e/ResultCacheEndToEndTest.php b/tests/e2e/ResultCacheEndToEndTest.php index d9a12e7a4a..e689bb4f6f 100644 --- a/tests/e2e/ResultCacheEndToEndTest.php +++ b/tests/e2e/ResultCacheEndToEndTest.php @@ -87,7 +87,7 @@ private function runPhpstanWithErrors(): void $this->assertSame('Parameter #1 $source of function token_get_all expects string, PhpParser\Node\Expr\MethodCall given.', $result['files'][$fileHelper->normalizePath(__DIR__ . '/PHP-Parser/lib/PhpParser/Lexer.php')]['messages'][0]['message']); $this->assertSame('Parameter #1 $code of method PhpParser\Lexer::startLexing() expects PhpParser\Node\Expr\MethodCall, string given.', $result['files'][$fileHelper->normalizePath(__DIR__ . '/PHP-Parser/lib/PhpParser/ParserAbstract.php')]['messages'][0]['message']); - $this->assertSame('Parameter #1 (array(\'foo\')) of echo cannot be converted to string.', $result['files'][$fileHelper->normalizePath(__DIR__ . '/PHP-Parser/lib/bootstrap.php')]['messages'][0]['message']); + $this->assertSame('Parameter #1 (array{\'foo\'}) of echo cannot be converted to string.', $result['files'][$fileHelper->normalizePath(__DIR__ . '/PHP-Parser/lib/bootstrap.php')]['messages'][0]['message']); $this->assertResultCache(__DIR__ . '/resultCache_2.php'); }