Skip to content

Commit 51d7431

Browse files
committed
Unify array shape description with PHPDoc type syntax
1 parent 2b3ee60 commit 51d7431

File tree

78 files changed

+443
-401
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+443
-401
lines changed

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ parameters:
235235
path: src/Rules/Api/ApiTraitUseRule.php
236236

237237
-
238-
message: "#^Binary operation \"\\+\" between array\\(class\\-string\\<TNodeType of PhpParser\\\\Node\\>\\) and array\\<string, class\\-string\\>\\|false results in an error\\.$#"
238+
message: "#^Binary operation \"\\+\" between array{class\\-string\\<TNodeType of PhpParser\\\\Node\\>} and array\\<string, class\\-string\\>\\|false results in an error\\.$#"
239239
count: 1
240240
path: src/Rules/Registry.php
241241

src/Type/Constant/ConstantArrayType.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,16 @@ public function describe(VerbosityLevel $level): string
728728
$exportValuesOnly = false;
729729
}
730730

731-
$items[] = sprintf('%s%s => %s', $isOptional ? '?' : '', var_export($keyType->getValue(), true), $valueType->describe($level));
731+
$keyDescription = $keyType->getValue();
732+
if (is_string($keyDescription)) {
733+
if (strpos($keyDescription, '"') !== false) {
734+
$keyDescription = sprintf('\'%s\'', $keyDescription);
735+
} elseif (strpos($keyDescription, '\'') !== false) {
736+
$keyDescription = sprintf('"%s"', $keyDescription);
737+
}
738+
}
739+
740+
$items[] = sprintf('%s%s: %s', $keyDescription, $isOptional ? '?' : '', $valueType->describe($level));
732741
$values[] = $valueType->describe($level);
733742
}
734743

@@ -740,7 +749,7 @@ public function describe(VerbosityLevel $level): string
740749
}
741750

742751
return sprintf(
743-
'array(%s%s)',
752+
'array{%s%s}',
744753
implode(', ', $exportValuesOnly ? $values : $items),
745754
$append
746755
);

0 commit comments

Comments
 (0)