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