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 typed properties #147

Merged
merged 1 commit into from
Aug 17, 2022

Conversation

bruceoutdoors
Copy link
Contributor

PHP doesn't allow typed properties to be accessed if it is uninitialized:

PHP Fatal error:  Uncaught Error: Typed property Order::$user_id must not be accessed before initialization

This change skips properties if it is not set. I know this library doesn't really support PHP type declarations, but this is a pretty harmless change that does not affect existing functionality (:

@codecov
Copy link

codecov bot commented Aug 17, 2022

Codecov Report

Merging #147 (6ad14f1) into master (0ee6870) will decrease coverage by 0.22%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #147      +/-   ##
==========================================
- Coverage   92.64%   92.41%   -0.23%     
==========================================
  Files          27       27              
  Lines        1686     1688       +2     
==========================================
- Hits         1562     1560       -2     
- Misses        124      128       +4     
Impacted Files Coverage Δ
src/Structure/ClassStructureTrait.php 90.54% <100.00%> (-5.30%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@vearutop
Copy link
Member

Thank you! 💪

@vearutop vearutop merged commit 9cf91be into swaggest:master Aug 17, 2022
@bruceoutdoors
Copy link
Contributor Author

Oh oo. I think those are valid points from the CI. Let me take a look

@vearutop
Copy link
Member

Hehe, no worries, I'll also look at it a bit later (and will fix red cross for cloc for external contributors).

@bruceoutdoors
Copy link
Contributor Author

Ah this change will break nullable fields. The correct implementation should be

// Get uninitialized properties as null
$value = isset($this->$propertyName) ? $this->$propertyName : null;

I'll send another PR. Apologies.

@bruceoutdoors bruceoutdoors deleted the support_typed_properties branch August 17, 2022 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants