Skip to content

Commit 414a476

Browse files
gen_stub: simplify ClassInfo::getRegistration()
1 parent a89adc8 commit 414a476

File tree

1 file changed

+16
-30
lines changed

1 file changed

+16
-30
lines changed

build/gen_stub.php

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3538,11 +3538,17 @@ function (Name $item) {
35383538
foreach ($this->propertyInfos as $property) {
35393539
$code .= $property->getDeclaration($allConstInfos);
35403540
}
3541+
// Reusable strings for wrapping conditional PHP 8.0+ code
3542+
if ($php80MinimumCompatibility) {
3543+
$php80CondStart = '';
3544+
$php80CondEnd = '';
3545+
} else {
3546+
$php80CondStart = "\n#if (PHP_VERSION_ID >= " . PHP_80_VERSION_ID . ")";
3547+
$php80CondEnd = "#endif\n";
3548+
}
35413549

35423550
if (!empty($this->attributes)) {
3543-
if (!$php80MinimumCompatibility) {
3544-
$code .= "\n#if (PHP_VERSION_ID >= " . PHP_80_VERSION_ID . ")";
3545-
}
3551+
$code .= $php80CondStart;
35463552

35473553
foreach ($this->attributes as $key => $attribute) {
35483554
$code .= $attribute->generateCode(
@@ -3553,45 +3559,25 @@ function (Name $item) {
35533559
);
35543560
}
35553561

3556-
if (!$php80MinimumCompatibility) {
3557-
$code .= "#endif\n";
3558-
}
3562+
$code .= $php80CondEnd;
35593563
}
35603564

35613565
if ($attributeInitializationCode = generateConstantAttributeInitialization($this->constInfos, $allConstInfos, $this->phpVersionIdMinimumCompatibility, $this->cond)) {
3562-
if (!$php80MinimumCompatibility) {
3563-
$code .= "#if (PHP_VERSION_ID >= " . PHP_80_VERSION_ID . ")";
3564-
}
3565-
3566+
$code .= $php80CondStart;
35663567
$code .= "\n" . $attributeInitializationCode;
3567-
3568-
if (!$php80MinimumCompatibility) {
3569-
$code .= "#endif\n";
3570-
}
3568+
$code .= $php80CondEnd;
35713569
}
35723570

35733571
if ($attributeInitializationCode = generatePropertyAttributeInitialization($this->propertyInfos, $allConstInfos, $this->phpVersionIdMinimumCompatibility)) {
3574-
if (!$php80MinimumCompatibility) {
3575-
$code .= "#if (PHP_VERSION_ID >= " . PHP_80_VERSION_ID . ")";
3576-
}
3577-
3572+
$code .= $php80CondStart;
35783573
$code .= "\n" . $attributeInitializationCode;
3579-
3580-
if (!$php80MinimumCompatibility) {
3581-
$code .= "#endif\n";
3582-
}
3574+
$code .= $php80CondEnd;
35833575
}
35843576

35853577
if ($attributeInitializationCode = generateFunctionAttributeInitialization($this->funcInfos, $allConstInfos, $this->phpVersionIdMinimumCompatibility, $this->cond)) {
3586-
if (!$php80MinimumCompatibility) {
3587-
$code .= "#if (PHP_VERSION_ID >= " . PHP_80_VERSION_ID . ")\n";
3588-
}
3589-
3578+
$code .= $php80CondStart;
35903579
$code .= "\n" . $attributeInitializationCode;
3591-
3592-
if (!$php80MinimumCompatibility) {
3593-
$code .= "#endif\n";
3594-
}
3580+
$code .= $php80CondEnd;
35953581
}
35963582

35973583
$code .= "\n\treturn class_entry;\n";

0 commit comments

Comments
 (0)