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

Commit 747ecce

Browse files
gen_stub: simplify ClassInfo::getRegistration()
1 parent 74f7ecb commit 747ecce

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

35983606
if (!empty($this->attributes)) {
3599-
if (!$php80MinimumCompatibility) {
3600-
$code .= "\n#if (PHP_VERSION_ID >= " . PHP_80_VERSION_ID . ")";
3601-
}
3607+
$code .= $php80CondStart;
36023608

36033609
foreach ($this->attributes as $key => $attribute) {
36043610
$code .= $attribute->generateCode(
@@ -3609,45 +3615,25 @@ function (Name $item) {
36093615
);
36103616
}
36113617

3612-
if (!$php80MinimumCompatibility) {
3613-
$code .= "#endif\n";
3614-
}
3618+
$code .= $php80CondEnd;
36153619
}
36163620

36173621
if ($attributeInitializationCode = generateConstantAttributeInitialization($this->constInfos, $allConstInfos, $this->phpVersionIdMinimumCompatibility, $this->cond)) {
3618-
if (!$php80MinimumCompatibility) {
3619-
$code .= "#if (PHP_VERSION_ID >= " . PHP_80_VERSION_ID . ")";
3620-
}
3621-
3622+
$code .= $php80CondStart;
36223623
$code .= "\n" . $attributeInitializationCode;
3623-
3624-
if (!$php80MinimumCompatibility) {
3625-
$code .= "#endif\n";
3626-
}
3624+
$code .= $php80CondEnd;
36273625
}
36283626

36293627
if ($attributeInitializationCode = generatePropertyAttributeInitialization($this->propertyInfos, $allConstInfos, $this->phpVersionIdMinimumCompatibility)) {
3630-
if (!$php80MinimumCompatibility) {
3631-
$code .= "#if (PHP_VERSION_ID >= " . PHP_80_VERSION_ID . ")";
3632-
}
3633-
3628+
$code .= $php80CondStart;
36343629
$code .= "\n" . $attributeInitializationCode;
3635-
3636-
if (!$php80MinimumCompatibility) {
3637-
$code .= "#endif\n";
3638-
}
3630+
$code .= $php80CondEnd;
36393631
}
36403632

36413633
if ($attributeInitializationCode = generateFunctionAttributeInitialization($this->funcInfos, $allConstInfos, $this->phpVersionIdMinimumCompatibility, $this->cond)) {
3642-
if (!$php80MinimumCompatibility) {
3643-
$code .= "#if (PHP_VERSION_ID >= " . PHP_80_VERSION_ID . ")\n";
3644-
}
3645-
3634+
$code .= $php80CondStart;
36463635
$code .= "\n" . $attributeInitializationCode;
3647-
3648-
if (!$php80MinimumCompatibility) {
3649-
$code .= "#endif\n";
3650-
}
3636+
$code .= $php80CondEnd;
36513637
}
36523638

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /