Skip to content

Commit 89eb11d

Browse files
gen_stub: simplify ClassInfo::getRegistration()
1 parent 8aca966 commit 89eb11d

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
@@ -3537,11 +3537,17 @@ function (Name $item) {
35373537
foreach ($this->propertyInfos as $property) {
35383538
$code .= $property->getDeclaration($allConstInfos);
35393539
}
3540+
// Reusable strings for wrapping conditional PHP 8.0+ code
3541+
if ($php80MinimumCompatibility) {
3542+
$php80CondStart = '';
3543+
$php80CondEnd = '';
3544+
} else {
3545+
$php80CondStart = "\n#if (PHP_VERSION_ID >= " . PHP_80_VERSION_ID . ")";
3546+
$php80CondEnd = "#endif\n";
3547+
}
35403548

35413549
if (!empty($this->attributes)) {
3542-
if (!$php80MinimumCompatibility) {
3543-
$code .= "\n#if (PHP_VERSION_ID >= " . PHP_80_VERSION_ID . ")";
3544-
}
3550+
$code .= $php80CondStart;
35453551

35463552
foreach ($this->attributes as $key => $attribute) {
35473553
$code .= $attribute->generateCode(
@@ -3552,45 +3558,25 @@ function (Name $item) {
35523558
);
35533559
}
35543560

3555-
if (!$php80MinimumCompatibility) {
3556-
$code .= "#endif\n";
3557-
}
3561+
$code .= $php80CondEnd;
35583562
}
35593563

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

35723570
if ($attributeInitializationCode = generatePropertyAttributeInitialization($this->propertyInfos, $allConstInfos, $this->phpVersionIdMinimumCompatibility)) {
3573-
if (!$php80MinimumCompatibility) {
3574-
$code .= "#if (PHP_VERSION_ID >= " . PHP_80_VERSION_ID . ")";
3575-
}
3576-
3571+
$code .= $php80CondStart;
35773572
$code .= "\n" . $attributeInitializationCode;
3578-
3579-
if (!$php80MinimumCompatibility) {
3580-
$code .= "#endif\n";
3581-
}
3573+
$code .= $php80CondEnd;
35823574
}
35833575

35843576
if ($attributeInitializationCode = generateFunctionAttributeInitialization($this->funcInfos, $allConstInfos, $this->phpVersionIdMinimumCompatibility, $this->cond)) {
3585-
if (!$php80MinimumCompatibility) {
3586-
$code .= "#if (PHP_VERSION_ID >= " . PHP_80_VERSION_ID . ")\n";
3587-
}
3588-
3577+
$code .= $php80CondStart;
35893578
$code .= "\n" . $attributeInitializationCode;
3590-
3591-
if (!$php80MinimumCompatibility) {
3592-
$code .= "#endif\n";
3593-
}
3579+
$code .= $php80CondEnd;
35943580
}
35953581

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

0 commit comments

Comments
 (0)