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

[Maker] Don't try to set read only properties #769

Open
KDederichs opened this issue Dec 23, 2024 · 4 comments
Open

[Maker] Don't try to set read only properties #769

KDederichs opened this issue Dec 23, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@KDederichs
Copy link
Contributor

Little bit of an DX improvement:

Every time I generate new factories using the make:facrory command it'll try to set createdAt by default even though that value has no setter (it's set in the constructor)

It would be awesome if the maker could skip over those read only properties so I don't have to go through all the factories manually and delete it :D

@nikophil nikophil added the enhancement New feature or request label Dec 23, 2024
@nikophil
Copy link
Member

nikophil commented Dec 23, 2024

Hi @KDederichs

yes, this sounds legit. Do you want to provide a PR?
I think a guard condition should be added in AbstractDefaultPropertyGuesser::addDefaultValueUsingFactory(), maybe using PropertyAccessor::isWritable(), I guess

@KDederichs
Copy link
Contributor Author

Sure I can look into it, I don't think that's the place for it though since that seems to be where it's adding defaults that are other factories specifically.

Also I don't think you could use PropertyAccessor there since that seems to relay on an object being present and at a quick glance I don't think we have the classname or an instance of it there

@nikophil
Copy link
Member

nikophil commented Dec 23, 2024

lol yeah sorry you're right, it's not the place to do it...

I wanted to find some place we can make this check once for all...

maybe in MakeFactoryData::getDefaultProperties(), you have everything you need there.

I'm just wondering what to do if always_force_properties: true is configured 🤔 I think, if this option is used, we should not skip those "readonly" properties

@KDederichs
Copy link
Contributor Author

Hmm getDefaultProperties is probably the right place to filter it out yes, but the fact that the property accessor only takes objects of the thing you want to inspect makes this a lot more complicated that I initially thought it would be.

It'd be all good if you assumed the user only has entities without constructor arguments since you then can grab the class and make a dummy object but I doubt that that's the case in real life :D

As for the always_force_properties probably yes, since the docs say it'll set the property directly without accessing the setters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

2 participants