Skip to content

Commit 6d2c1ed

Browse files
DanielEScherzerkocsismate
authored andcommitted
gen_stub: move createAttributes() into AttributeInfo
Reduce the number of global functions by moving it to `AttributeInfo::createFromGroups()`. In the process, fix the documentation for the return type, the result is an array of `AttributeInfo` objects, not `Attribute` objects.
1 parent 2d185e4 commit 6d2c1ed

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

build/gen_stub.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3229,6 +3229,22 @@ public function generateCode(string $invocation, string $nameSuffix, array $allC
32293229
}
32303230
return $code;
32313231
}
3232+
3233+
/**
3234+
* @param array<int, array<int, AttributeGroup>> $attributeGroups
3235+
* @return AttributeInfo[]
3236+
*/
3237+
public static function createFromGroups(array $attributeGroups): array {
3238+
$attributes = [];
3239+
3240+
foreach ($attributeGroups as $attrGroup) {
3241+
foreach ($attrGroup->attrs as $attr) {
3242+
$attributes[] = new AttributeInfo($attr->name->toString(), $attr->args);
3243+
}
3244+
}
3245+
3246+
return $attributes;
3247+
}
32323248
}
32333249

32343250
class ClassInfo {
@@ -4426,7 +4442,7 @@ function parseFunctionLike(
44264442
$type,
44274443
isset($docParamTypes[$varName]) ? Type::fromString($docParamTypes[$varName]) : null,
44284444
$param->default ? $prettyPrinter->prettyPrintExpr($param->default) : null,
4429-
createAttributes($param->attrGroups)
4445+
AttributeInfo::createFromGroups($param->attrGroups)
44304446
);
44314447
if (!$param->default && !$param->variadic) {
44324448
$numRequiredArgs = $i + 1;
@@ -4465,7 +4481,7 @@ function parseFunctionLike(
44654481
$cond,
44664482
$isUndocumentable,
44674483
$minimumPhpVersionIdCompatibility,
4468-
createAttributes($func->attrGroups),
4484+
AttributeInfo::createFromGroups($func->attrGroups),
44694485
$framelessFunctionInfos,
44704486
ExposedDocComment::extractExposedComment($comments)
44714487
);
@@ -4656,7 +4672,7 @@ function parseClass(
46564672
}
46574673
}
46584674

4659-
$attributes = createAttributes($class->attrGroups);
4675+
$attributes = AttributeInfo::createFromGroups($class->attrGroups);
46604676
foreach ($attributes as $attribute) {
46614677
switch ($attribute->class) {
46624678
case 'AllowDynamicProperties':
@@ -4720,22 +4736,6 @@ function parseClass(
47204736
);
47214737
}
47224738

4723-
/**
4724-
* @param array<int, array<int, AttributeGroup>> $attributeGroups
4725-
* @return Attribute[]
4726-
*/
4727-
function createAttributes(array $attributeGroups): array {
4728-
$attributes = [];
4729-
4730-
foreach ($attributeGroups as $attrGroup) {
4731-
foreach ($attrGroup->attrs as $attr) {
4732-
$attributes[] = new AttributeInfo($attr->name->toString(), $attr->args);
4733-
}
4734-
}
4735-
4736-
return $attributes;
4737-
}
4738-
47394739
function handlePreprocessorConditions(array &$conds, Stmt $stmt): ?string {
47404740
foreach ($stmt->getComments() as $comment) {
47414741
$text = trim($comment->getText());
@@ -4855,7 +4855,7 @@ function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstrac
48554855
$cond,
48564856
$fileInfo->isUndocumentable,
48574857
$fileInfo->getMinimumPhpVersionIdCompatibility(),
4858-
createAttributes($classStmt->attrGroups)
4858+
AttributeInfo::createFromGroups($classStmt->attrGroups)
48594859
);
48604860
}
48614861
} else if ($classStmt instanceof Stmt\Property) {
@@ -4872,7 +4872,7 @@ function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstrac
48724872
$classStmt->getComments(),
48734873
$prettyPrinter,
48744874
$fileInfo->getMinimumPhpVersionIdCompatibility(),
4875-
createAttributes($classStmt->attrGroups)
4875+
AttributeInfo::createFromGroups($classStmt->attrGroups)
48764876
);
48774877
}
48784878
} else if ($classStmt instanceof Stmt\ClassMethod) {

0 commit comments

Comments
 (0)