Skip to content

Add simple option to assert entity contain relations. #116

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

Merged
merged 3 commits into from
Mar 24, 2025

Conversation

dereuromark
Copy link
Owner

@dereuromark dereuromark commented Mar 24, 2025

// in some service method at the beginning
public function buildPdf(Product $product): string {
    $product->require('supplier.company.state.country')

    //Render template
}

This avoids the usual kind of hidden and not speaking

warning: 2 :: Attempt to read property "sku" on null

deprecated: 8192 :: strlen(): Passing null to parameter #1 ($string) of type string is deprecated

warning: 2 :: foreach() argument must be of type array|object, null given

etc then inside the business logic or rendering.


For hasMany relations this might be a bit trickier and for now maybe out of scope

$product->require('parts.0.company.state.country')

would be the current working solution if we expect parts to always have > 0 records and integer increments.

We could use {n} or {?n} to indicate either any number / numeric key or with ? to make parts optionally also empty:

$product->require('parts.{?n}.company.state.country')

@codecov-commenter
Copy link

codecov-commenter commented Mar 24, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 86.95652% with 3 lines in your changes missing coverage. Please review.

Project coverage is 83.22%. Comparing base (b4aef4b) to head (af7e4b3).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/Model/Entity/RequireTrait.php 86.95% 3 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #116      +/-   ##
============================================
+ Coverage     83.17%   83.22%   +0.05%     
- Complexity      728      739      +11     
============================================
  Files            30       31       +1     
  Lines          1676     1699      +23     
============================================
+ Hits           1394     1414      +20     
- Misses          282      285       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dereuromark dereuromark merged commit 0bf8617 into master Mar 24, 2025
16 checks passed
@dereuromark dereuromark deleted the entity-require-path branch March 24, 2025 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants