Skip to content

Commit 4d78964

Browse files
gen_stub: simplify ClassInfo::getRegistration()
1 parent 48acabf commit 4d78964

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
@@ -3596,11 +3596,17 @@ function (Name $item) {
35963596
foreach ($this->propertyInfos as $property) {
35973597
$code .= $property->getDeclaration($allConstInfos);
35983598
}
3599+
// Reusable strings for wrapping conditional PHP 8.0+ code
3600+
if ($php80MinimumCompatibility) {
3601+
$php80CondStart = '';
3602+
$php80CondEnd = '';
3603+
} else {
3604+
$php80CondStart = "\n#if (PHP_VERSION_ID >= " . PHP_80_VERSION_ID . ")";
3605+
$php80CondEnd = "#endif\n";
3606+
}
35993607

36003608
if (!empty($this->attributes)) {
3601-
if (!$php80MinimumCompatibility) {
3602-
$code .= "\n#if (PHP_VERSION_ID >= " . PHP_80_VERSION_ID . ")";
3603-
}
3609+
$code .= $php80CondStart;
36043610

36053611
foreach ($this->attributes as $key => $attribute) {
36063612
$code .= $attribute->generateCode(
@@ -3611,45 +3617,25 @@ function (Name $item) {
36113617
);
36123618
}
36133619

3614-
if (!$php80MinimumCompatibility) {
3615-
$code .= "#endif\n";
3616-
}
3620+
$code .= $php80CondEnd;
36173621
}
36183622

36193623
if ($attributeInitializationCode = generateConstantAttributeInitialization($this->constInfos, $allConstInfos, $this->phpVersionIdMinimumCompatibility, $this->cond)) {
3620-
if (!$php80MinimumCompatibility) {
3621-
$code .= "#if (PHP_VERSION_ID >= " . PHP_80_VERSION_ID . ")";
3622-
}
3623-
3624+
$code .= $php80CondStart;
36243625
$code .= "\n" . $attributeInitializationCode;
3625-
3626-
if (!$php80MinimumCompatibility) {
3627-
$code .= "#endif\n";
3628-
}
3626+
$code .= $php80CondEnd;
36293627
}
36303628

36313629
if ($attributeInitializationCode = generatePropertyAttributeInitialization($this->propertyInfos, $allConstInfos, $this->phpVersionIdMinimumCompatibility)) {
3632-
if (!$php80MinimumCompatibility) {
3633-
$code .= "#if (PHP_VERSION_ID >= " . PHP_80_VERSION_ID . ")";
3634-
}
3635-
3630+
$code .= $php80CondStart;
36363631
$code .= "\n" . $attributeInitializationCode;
3637-
3638-
if (!$php80MinimumCompatibility) {
3639-
$code .= "#endif\n";
3640-
}
3632+
$code .= $php80CondEnd;
36413633
}
36423634

36433635
if ($attributeInitializationCode = generateFunctionAttributeInitialization($this->funcInfos, $allConstInfos, $this->phpVersionIdMinimumCompatibility, $this->cond)) {
3644-
if (!$php80MinimumCompatibility) {
3645-
$code .= "#if (PHP_VERSION_ID >= " . PHP_80_VERSION_ID . ")\n";
3646-
}
3647-
3636+
$code .= $php80CondStart;
36483637
$code .= "\n" . $attributeInitializationCode;
3649-
3650-
if (!$php80MinimumCompatibility) {
3651-
$code .= "#endif\n";
3652-
}
3638+
$code .= $php80CondEnd;
36533639
}
36543640

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

0 commit comments

Comments
 (0)