Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.15.0] Inserting AllowDynamicProperties attribute breaks final classes #1516

Closed
tminich opened this issue Feb 15, 2024 · 4 comments
Closed
Labels

Comments

@tminich
Copy link

tminich commented Feb 15, 2024

Versions:

  • ide-helper Version: 2.15.0
  • Laravel Version: 10.44.0
  • PHP Version: 8.2.15

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:

  • Declare a model class final
  • Generate model helper (with -M -R, not sure if and how far that matters)
@tminich tminich added the bug label Feb 15, 2024
@mfn
Copy link
Collaborator

mfn commented Feb 15, 2024

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

$output = "namespace {$namespace}{\n{$docComment}\n\t{$keyword}{$allowDynamicAttributes}class {$classname} ";
?

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
Copy link
Owner

Does this fix it for you? #1517

@barryvdh
Copy link
Owner

barryvdh commented Feb 15, 2024

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

$output = "namespace {$namespace}{\n{$docComment}\n\t{$keyword}{$allowDynamicAttributes}class {$classname} ";

Yeah that fixes it, according to the tests

@tminich
Copy link
Author

tminich commented Feb 16, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants