Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit03341cc

Browse files
committed
Nicer type descriptions usable in PHPDocs
1 parentf7d232a commit03341cc

File tree

52 files changed

+333
-284
lines changed

Some content is hidden

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

52 files changed

+333
-284
lines changed

‎build/baseline-8.0.neon‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ parameters:
1111
path:../src/Type/Php/MbFunctionsReturnTypeExtension.php
1212

1313
-
14-
message:"#^Strict comparison using\\=\\=\\= between array<int, string>&nonEmpty and false will always evaluate to false\\.$#"
14+
message:"#^Strict comparison using\\=\\=\\= betweennon-empty-array<int, string> and false will always evaluate to false\\.$#"
1515
count:1
1616
path:../src/Type/Php/StrSplitFunctionReturnTypeExtension.php
1717

‎phpstan-baseline.neon‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ parameters:
259259
count:1
260260
path:src/Testing/PHPStanTestCase.php
261261

262+
-
263+
message:"#^Call to function in_array\\(\\) with arguments 'array', array\\<int, 'array'\\|'string'\\> and true will always evaluate to true\\.$#"
264+
count:1
265+
path:src/Type/IntersectionType.php
266+
262267
-
263268
message:
264269
"""

‎src/Type/Accessory/AccessoryNumericStringType.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function equals(Type $type): bool
8484

8585
publicfunctiondescribe(\PHPStan\Type\VerbosityLevel$level):string
8686
{
87-
return'numeric';
87+
return'numeric-string';
8888
}
8989

9090
publicfunctionisOffsetAccessible():TrinaryLogic

‎src/Type/Accessory/NonEmptyArrayType.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function equals(Type $type): bool
8383

8484
publicfunctiondescribe(\PHPStan\Type\VerbosityLevel$level):string
8585
{
86-
return'nonEmpty';
86+
return'non-empty-array';
8787
}
8888

8989
publicfunctionisOffsetAccessible():TrinaryLogic

‎src/Type/IntersectionType.php‎

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -149,45 +149,75 @@ function () use ($level): string {
149149
returnimplode('&',$typeNames);
150150
},
151151
function ()use ($level):string {
152-
$typeNames = [];
153-
$accessoryTypes = [];
154-
foreach ($this->typesas$type) {
155-
if ($typeinstanceof AccessoryNonEmptyStringType ||$typeinstanceof AccessoryLiteralStringType) {
156-
$accessoryTypes[] =$type;
157-
}
158-
if ($typeinstanceof AccessoryType && !$typeinstanceof AccessoryNumericStringType && !$typeinstanceof NonEmptyArrayType && !$typeinstanceof AccessoryNonEmptyStringType) {
159-
continue;
160-
}
161-
$typeNames[] =$type->describe($level);
162-
}
163-
164-
if (count($accessoryTypes) >0) {
165-
returnimplode('&',array_map(staticfunction (Type$type)use ($level):string {
166-
return$type->describe($level);
167-
},$accessoryTypes));
168-
}
169-
170-
returnimplode('&',$typeNames);
152+
return$this->describeItself($level,true);
171153
},
172154
function ()use ($level):string {
173-
$typeNames = [];
174-
$accessoryTypes = [];
175-
foreach ($this->typesas$type) {
176-
if ($typeinstanceof AccessoryNonEmptyStringType ||$typeinstanceof AccessoryLiteralStringType) {
177-
$accessoryTypes[] =$type;
155+
return$this->describeItself($level,false);
156+
}
157+
);
158+
}
159+
160+
privatefunctiondescribeItself(VerbosityLevel$level,bool$skipAccessoryTypes):string
161+
{
162+
$typesToDescribe = [];
163+
$skipTypeNames = [];
164+
foreach ($this->typesas$type) {
165+
if ($typeinstanceof AccessoryNonEmptyStringType ||$typeinstanceof AccessoryLiteralStringType ||$typeinstanceof AccessoryNumericStringType) {
166+
$typesToDescribe[] =$type;
167+
$skipTypeNames[] ='string';
168+
continue;
169+
}
170+
if ($typeinstanceof NonEmptyArrayType) {
171+
$typesToDescribe[] =$type;
172+
$skipTypeNames[] ='array';
173+
continue;
174+
}
175+
176+
if ($skipAccessoryTypes) {
177+
continue;
178+
}
179+
180+
if (!$typeinstanceof AccessoryType) {
181+
continue;
182+
}
183+
184+
$typesToDescribe[] =$type;
185+
}
186+
187+
$describedTypes = [];
188+
foreach ($this->typesas$type) {
189+
if ($typeinstanceof AccessoryType) {
190+
continue;
191+
}
192+
$typeDescription =$type->describe($level);
193+
if (
194+
substr($typeDescription,0,strlen('array<')) ==='array<'
195+
&&in_array('array',$skipTypeNames,true)
196+
) {
197+
foreach ($typesToDescribeas$j =>$typeToDescribe) {
198+
if (!$typeToDescribeinstanceof NonEmptyArrayType) {
199+
continue;
178200
}
179-
$typeNames[] =$type->describe($level);
180-
}
181201

182-
if (count($accessoryTypes) >0) {
183-
returnimplode('&',array_map(staticfunction (Type$type)use ($level):string {
184-
return$type->describe($level);
185-
},$accessoryTypes));
202+
unset($typesToDescribe[$j]);
186203
}
187204

188-
returnimplode('&',$typeNames);
205+
$describedTypes[] ='non-empty-array<' .substr($typeDescription,strlen('array<'));
206+
continue;
189207
}
190-
);
208+
209+
if (in_array($typeDescription,$skipTypeNames,true)) {
210+
continue;
211+
}
212+
213+
$describedTypes[] =$type->describe($level);
214+
}
215+
216+
foreach ($typesToDescribeas$typeToDescribe) {
217+
$describedTypes[] =$typeToDescribe->describe($level);
218+
}
219+
220+
returnimplode('&',$describedTypes);
191221
}
192222

193223
publicfunctioncanAccessProperties():TrinaryLogic

‎src/Type/VerbosityLevel.php‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ public static function getRecommendedLevelByType(Type $acceptingType, ?Type $acc
6969
$moreVerbose =true;
7070
return$type;
7171
}
72-
if ($typeinstanceof AccessoryNumericStringType ||$typeinstanceof AccessoryNonEmptyStringType ||$typeinstanceof AccessoryLiteralStringType) {
73-
$moreVerbose =true;
74-
return$type;
75-
}
76-
if ($typeinstanceof NonEmptyArrayType) {
72+
if (
73+
// synced with IntersectionType::describe()
74+
$typeinstanceof AccessoryNonEmptyStringType
75+
||$typeinstanceof AccessoryLiteralStringType
76+
||$typeinstanceof AccessoryNumericStringType
77+
||$typeinstanceof NonEmptyArrayType
78+
) {
7779
$moreVerbose =true;
7880
return$type;
7981
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp