-
Notifications
You must be signed in to change notification settings - Fork 17
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
feat: option to generate code with strict types #180
Conversation
👍 for this thanks, can you add the possibility to configure this through the Also wondering if declare strict should be true by default ? poke @Korbeil @nikophil ? If you could update the doc and add a note in the changelog it would be nice, if you are not comfortable doing so we can do it. |
I'm totally for this option and I think we should put it by default as @joelwurtz stated. |
won't we face some BC break if this becomes a default thing? |
Made it configurable from |
@@ -24,7 +24,8 @@ public function __construct( | |||
public readonly array $propertiesMetadata, | |||
public readonly bool $checkAttributes = true, | |||
public readonly ConstructorStrategy $constructorStrategy = ConstructorStrategy::AUTO, | |||
public bool $allowReadOnlyTargetToPopulate = false, | |||
public readonly bool $allowReadOnlyTargetToPopulate = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like readonly was missed here
This is right, we should put it disabled by default and we will put it enabled by default on next major ~ |
f698c8e
to
3bc006a
Compare
@Korbeil Done👍 |
3bc006a
to
0531fcc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👌
Could you add a note about your feature into the CHANGELOG please ?
0531fcc
to
91369ab
Compare
Added note to CHANGELOG and combined everything in 1 commit |
Thanks for the feature @MrMeshok ! 🙏 |
PHP, by default, will coerce values of the wrong type into the expected scalar type declaration if possible. This leads to unexpected behavior. For example, losing decimal digits when casting float to int
This PR adds configuration to add
declare(strict_types=1)
to generated code when mapping, so instead of unexpected behavior, you get TypeError.If everything is ok, I will update the docs, but I am not very fluent with english, so maybe someone else could write a more understandable description.