barryvdh / laravel-ide-helper

IDE Helper for Laravel
MIT License
14.17k stars 1.16k forks source link

[2.15.0] Inserting AllowDynamicProperties attribute breaks final classes #1516

Closed tminich closed 7 months ago

tminich commented 7 months ago

Versions:

Description:

Apparently 2.15.0 introduced adding the AllowDynamicProperties attribute to generated model helper classes. Unfortunately, if the model class is declared final, this attribute is inserted between the final and class keywords leading to invalid php.

    final #[\AllowDynamicProperties]
    class IdeHelperParticipant {}

Steps To Reproduce:

mfn commented 7 months ago

I guess we just need to shuffle $keyword and $allowDynamicAttributes in https://github.com/barryvdh/laravel-ide-helper/blob/c119e89cf044fd56a98cc92ac0bfc3c8d148b9ea/src/Console/ModelsCommand.php#L1086 ?

Do you want to make a PR, including a test using final (ideally also abstract, which is also covered in \Barryvdh\LaravelIdeHelper\Console\ModelsCommand::getClassKeyword

barryvdh commented 7 months ago

Does this fix it for you? https://github.com/barryvdh/laravel-ide-helper/pull/1517

barryvdh commented 7 months ago

I guess we just need to shuffle $keyword and $allowDynamicAttributes in

https://github.com/barryvdh/laravel-ide-helper/blob/c119e89cf044fd56a98cc92ac0bfc3c8d148b9ea/src/Console/ModelsCommand.php#L1086

Yeah that fixes it, according to the tests

tminich commented 7 months ago

Looks like it's fixed in 1.5.1, thanks a lot!