@@ -3594,11 +3594,17 @@ function (Name $item) {
3594
3594
foreach ($ this ->propertyInfos as $ property ) {
3595
3595
$ code .= $ property ->getDeclaration ($ allConstInfos );
3596
3596
}
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
+ }
3597
3605
3598
3606
if (!empty ($ this ->attributes )) {
3599
- if (!$ php80MinimumCompatibility ) {
3600
- $ code .= "\n#if (PHP_VERSION_ID >= " . PHP_80_VERSION_ID . ") " ;
3601
- }
3607
+ $ code .= $ php80CondStart ;
3602
3608
3603
3609
foreach ($ this ->attributes as $ key => $ attribute ) {
3604
3610
$ code .= $ attribute ->generateCode (
@@ -3609,45 +3615,25 @@ function (Name $item) {
3609
3615
);
3610
3616
}
3611
3617
3612
- if (!$ php80MinimumCompatibility ) {
3613
- $ code .= "#endif \n" ;
3614
- }
3618
+ $ code .= $ php80CondEnd ;
3615
3619
}
3616
3620
3617
3621
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 ;
3622
3623
$ code .= "\n" . $ attributeInitializationCode ;
3623
-
3624
- if (!$ php80MinimumCompatibility ) {
3625
- $ code .= "#endif \n" ;
3626
- }
3624
+ $ code .= $ php80CondEnd ;
3627
3625
}
3628
3626
3629
3627
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 ;
3634
3629
$ code .= "\n" . $ attributeInitializationCode ;
3635
-
3636
- if (!$ php80MinimumCompatibility ) {
3637
- $ code .= "#endif \n" ;
3638
- }
3630
+ $ code .= $ php80CondEnd ;
3639
3631
}
3640
3632
3641
3633
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 ;
3646
3635
$ code .= "\n" . $ attributeInitializationCode ;
3647
-
3648
- if (!$ php80MinimumCompatibility ) {
3649
- $ code .= "#endif \n" ;
3650
- }
3636
+ $ code .= $ php80CondEnd ;
3651
3637
}
3652
3638
3653
3639
$ code .= "\n\treturn class_entry; \n" ;
0 commit comments