Skip to content

Add Closures::unfold function - #64

Merged
frankdekker merged 6 commits into
123inkt:masterfrom
RubenKluft:closures
Mar 5, 2026
Merged

Add Closures::unfold function#64
frankdekker merged 6 commits into
123inkt:masterfrom
RubenKluft:closures

Conversation

@RubenKluft

@RubenKluft RubenKluft commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

Utility function to replace the repeated pattern of

  if ($this->service instanceof Closure) {
      $this->service = ($this->service )();
  }

  return $this->service ; 

That is often used to make lazy loaded services

Copilot AI review requested due to automatic review settings March 5, 2026 11:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new DR\Utils\Closures helper to “unfold” a closure into its resolved object value (memoizing by replacing the referenced variable), plus a unit test covering the new behavior.

Changes:

  • Introduce Closures::unfold(object &$closure): object to resolve a Closure once and overwrite the referenced variable with the resolved object.
  • Add ClosuresTest::testUnfold() to validate the new helper.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Closures.php Adds the Closures utility class with the new unfold method and PHPStan typing annotations.
tests/Unit/ClosuresTest.php Adds a unit test for Closures::unfold.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread tests/Unit/ClosuresTest.php Outdated
Comment thread src/Closures.php Outdated
@frankdekker
frankdekker merged commit e1e841e into 123inkt:master Mar 5, 2026
12 checks passed
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.

3 participants