-
-
Notifications
You must be signed in to change notification settings - Fork 840
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
fix: set nullable true when default value is null #2390
base: master
Are you sure you want to change the base?
fix: set nullable true when default value is null #2390
Conversation
4357ef7
to
9c775b0
Compare
9c775b0
to
3cb0e0c
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2390 +/- ##
==========================================
+ Coverage 89.50% 89.53% +0.03%
==========================================
Files 78 78
Lines 2896 2915 +19
==========================================
+ Hits 2592 2610 +18
- Misses 304 305 +1 ☔ View full report in Codecov by Sentry. |
2ee2ccd
to
7489b46
Compare
When reflection shows that the default parameter of a a property is null, then the `nullable` parameter is set to `true` for that property. Currently that needs to be set via the attribute but that is a bit redundant as the information is already available from reflection This change only does that for properties and for setter methods. Right now getter methods that allow a null value to be returned are not taken into account for setting the `nullable` property.
7489b46
to
318d00d
Compare
@@ -134,12 +146,49 @@ public function getDefaultFromPropertyReflection(\ReflectionProperty $reflection | |||
return Generator::UNDEFINED; | |||
} | |||
|
|||
$defaultValue = $reflection->getDeclaringClass()->getDefaultProperties()[$propertyName] ?? null; | |||
if (PHP_VERSION_ID < 80000) { |
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.
Why does this need to check the PHP version? I would rather this not be the case because the next major 5.x
will move to PHP 8.1 minimum
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.
As hasDefaultValue
and getDefaultValue
are only available since PHP8.0 I needed this "workaround" for the PHP7 users that uses a quirky way of getting the default values. That way also does not take into account possible DocBlock types so it might report back an unexpected default value when an implicit null
is set. In PHP8.0 and higher we check for DocBlock type-infos to make a possible NULL default value plausible or not.
In he next major release this part can safely be removed as PHP8.1 supports the required functions 😉
Description
When reflection shows that the default parameter of a a property is null, then the
nullable
parameter is set totrue
for that property.Currently that needs to be set via the attribute but that is a bit redundant as the information is already available from reflection
This change only does that for properties and for setter methods.
Right now getter methods that allow a null value to be returned are not taken into account for setting the
nullable
property.This resets the state prior to v4.25.0 and is related to #2330
This is a refactor of #2377
What type of PR is this? (check all applicable)
Checklist
docs/
)CHANGELOG.md
)