xsd2php icon indicating copy to clipboard operation
xsd2php copied to clipboard

Add nullable strict types for native and simple arguments

Open rvdbogerd opened this issue 4 years ago • 4 comments

Just wanted to discuss this with you.. I have had a fork of this repo for a long time, with below addition. It forces strict types for scalar and simple arguments, which is way cleaner for my static analyser etc. I did, however, add a nullable default type for all values, as I don't know exactly how to determine if a value should be nullable or not.

What do you think about this? Have you tried to add strict types before or do you still want to be BC with php < 7?

rvdbogerd avatar Jan 11 '21 20:01 rvdbogerd

hmm, this is not a bad idea TBH. it requires php 7 (but nowadays everyone should be on php7).

regarding the NULL option, it makes sense too. for some cases it should possible to detect if NULL is allowed but IMO is not particularly worth. the only possible improvements i could have in mind is to make this an opt-in feature via some config parameter

goetas avatar Jan 12 '21 13:01 goetas

You mean something like this? I don't have time to dive into the tests right now, but it's a start.

rvdbogerd avatar Jan 29 '21 12:01 rvdbogerd

@rvdbogerd yea, that was the idea

goetas avatar Jun 18 '21 07:06 goetas

Apologies for the late answer, if you are still working on this, i'm happy to continue reviewing it

goetas avatar Jun 18 '21 07:06 goetas

@rvdbogerd this looks good to me. is it ready? if yes, i can merge it right away

goetas avatar Oct 23 '22 17:10 goetas

@rvdbogerd this looks good to me. is it ready? if yes, i can merge it right away

Yes, please do! I've been running it in production for years, so should be working :)

rvdbogerd avatar Oct 30 '22 13:10 rvdbogerd

Hi @goetas! Could you merge this please?

rvdbogerd avatar Dec 16 '22 12:12 rvdbogerd

looks good, thanks!

goetas avatar Dec 20 '22 21:12 goetas

sorry for the dumb question but how to enable strict types in configuration?

metalinspired avatar Jan 19 '23 09:01 metalinspired

sorry for the dumb question but how to enable strict types in configuration?

You can initialize the ClassGenerator like this:

$generator = new ClassGenerator(true);

rvdbogerd avatar Jan 19 '23 10:01 rvdbogerd