@@ -3537,11 +3537,17 @@ function (Name $item) {
3537
3537
foreach ($ this ->propertyInfos as $ property ) {
3538
3538
$ code .= $ property ->getDeclaration ($ allConstInfos );
3539
3539
}
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
+ }
3540
3548
3541
3549
if (!empty ($ this ->attributes )) {
3542
- if (!$ php80MinimumCompatibility ) {
3543
- $ code .= "\n#if (PHP_VERSION_ID >= " . PHP_80_VERSION_ID . ") " ;
3544
- }
3550
+ $ code .= $ php80CondStart ;
3545
3551
3546
3552
foreach ($ this ->attributes as $ key => $ attribute ) {
3547
3553
$ code .= $ attribute ->generateCode (
@@ -3552,45 +3558,25 @@ function (Name $item) {
3552
3558
);
3553
3559
}
3554
3560
3555
- if (!$ php80MinimumCompatibility ) {
3556
- $ code .= "#endif \n" ;
3557
- }
3561
+ $ code .= $ php80CondEnd ;
3558
3562
}
3559
3563
3560
3564
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 ;
3565
3566
$ code .= "\n" . $ attributeInitializationCode ;
3566
-
3567
- if (!$ php80MinimumCompatibility ) {
3568
- $ code .= "#endif \n" ;
3569
- }
3567
+ $ code .= $ php80CondEnd ;
3570
3568
}
3571
3569
3572
3570
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 ;
3577
3572
$ code .= "\n" . $ attributeInitializationCode ;
3578
-
3579
- if (!$ php80MinimumCompatibility ) {
3580
- $ code .= "#endif \n" ;
3581
- }
3573
+ $ code .= $ php80CondEnd ;
3582
3574
}
3583
3575
3584
3576
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 ;
3589
3578
$ code .= "\n" . $ attributeInitializationCode ;
3590
-
3591
- if (!$ php80MinimumCompatibility ) {
3592
- $ code .= "#endif \n" ;
3593
- }
3579
+ $ code .= $ php80CondEnd ;
3594
3580
}
3595
3581
3596
3582
$ code .= "\n\treturn class_entry; \n" ;
0 commit comments