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

Support of record fields default values #13

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

SokolovAlexanderV
Copy link

@SokolovAlexanderV SokolovAlexanderV commented Apr 17, 2024

Closes #12

@SokolovAlexanderV SokolovAlexanderV requested a review from a team as a code owner April 17, 2024 10:32
@SokolovAlexanderV SokolovAlexanderV changed the title Support of record fields default values closes Support of record fields default values Apr 17, 2024
@SokolovAlexanderV SokolovAlexanderV changed the title closes Support of record fields default values Support of record fields default values Apr 17, 2024
@@ -103,7 +103,7 @@ private function validateFields(array $schemaFields, array $payload, string $pat
}

$types = isset($rule['type']['type']) ? [$rule['type']] : (array) $rule['type'];
$fieldValue = $payload[$fieldName];
$fieldValue = $payload[$fieldName] ?? $rule['default'];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be better to check with array_key_exists instead of the null coalescing operator ??:
$fieldValue = array_key_exists($fieldName, $payload) ? $payload[$fieldName] : $rule['default']

Because if $payload[$fieldName] exists but its value is null, then ?? will cause $rule['default'] to be assigned when it shouldn't.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's better way. Added changes.

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

Successfully merging this pull request may close these issues.

Support of record fields default values
2 participants