Skip to content

Namespace value() helper to avoid conflicts with host applications#11

Merged
bashgeek merged 2 commits into
mainfrom
fix-namespace-helpers
Apr 20, 2026
Merged

Namespace value() helper to avoid conflicts with host applications#11
bashgeek merged 2 commits into
mainfrom
fix-namespace-helpers

Conversation

@bashgeek

Copy link
Copy Markdown
Contributor

Summary

  • Added namespace CoyoteCert\Support; to src/Support/helpers.php so the value() function lives at CoyoteCert\Support\value() instead of the global namespace
  • Updated the function_exists() guard to check __NAMESPACE__ . '\\value' rather than the bare string 'value'
  • Added use Closure; import (required once the file has a namespace declaration)
  • Added use function CoyoteCert\Support\value; to HelpersTest.php so the test file can still resolve the function without a namespace of its own

Why

As a Composer package, defining value() in the global namespace collides with the identically-named helper shipped by Laravel, Illuminate, and other popular packages. Any host application that already defines or imports value() would trigger a fatal redeclaration error at autoload time. Namespacing the function eliminates the conflict entirely.

Arr.php (the only internal caller) required no changes — it already lives in CoyoteCert\Support, so PHP resolves the unqualified value() call to the same namespace automatically.

Test plan

  • vendor/bin/pest tests/Unit/Support/ passes (134 assertions, all green)
  • No changes required to Arr.php — verified via existing ArrTest suite

@codecov-commenter

codecov-commenter commented Apr 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Namespaced functions cannot collide with global ones, and Composer's
files autoload guarantees single-load, so the guard is unnecessary.
Removing it also makes the function definition unconditionally coverable.
@bashgeek bashgeek merged commit 3f592ad into main Apr 20, 2026
10 checks passed
@bashgeek bashgeek deleted the fix-namespace-helpers branch April 20, 2026 13:28
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