Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/collections/src/Traits/EnumeratesValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Hypervel\Support\Collection;
use Hypervel\Support\Enumerable;
use Hypervel\Support\HigherOrderCollectionProxy;
use Hypervel\Database\Eloquent\Casts\Json;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Collections now require database

If hypervel/collections is installed without hypervel/database, the new Json call cannot load its class: collections does not require the database package, and the database package owns that class. Calling toJson(), toPrettyJson(), or casting a collection to a string now fails with a class-not-found error instead of producing JSON.

Fix in Claude Code Fix in Codex

use JsonException;
use JsonSerializable;
use Stringable;
Expand Down Expand Up @@ -965,7 +966,7 @@ public function jsonSerialize(): array
*/
public function toJson(int $options = 0): string
{
return json_encode($this->jsonSerialize(), $options | JSON_THROW_ON_ERROR);
return Json::encode($this->jsonSerialize(), $options | JSON_THROW_ON_ERROR);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

1. Standalone collections cannot serialize 🐞 Bug ≡ Correctness

EnumeratesValues::toJson() now calls Hypervel\Database\Eloquent\Casts\Json, although the
collections package neither requires nor autoloads the database package. Calling toJson() in a
standalone hypervel/collections installation therefore reaches an unavailable class and terminates
with a class-not-found error.
Agent Prompt
## Issue description
Collection JSON serialization now depends on an Eloquent class from `hypervel/database`, which is not a dependency of the standalone collections package and itself depends on collections.

## Fix Focus Areas
- src/collections/src/Traits/EnumeratesValues.php[17-17]
- src/collections/src/Traits/EnumeratesValues.php[967-969]

## Recommended Fix
Remove the database `Json` import and restore direct `json_encode` with `JSON_THROW_ON_ERROR`, preserving collection serialization without introducing a circular package dependency.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

2. Model encoders corrupt collections 🐞 Bug ≡ Correctness

EnumeratesValues::toJson() now delegates to the Eloquent cast encoder, whose process-wide callback
can return any mixed value instead of native JSON. When an application configures that supported
callback for model attributes, every collection starts returning the callback's arbitrary output or
throws a return-type error if it returns false.
Agent Prompt
## Issue description
Collection serialization now shares Eloquent's configurable global encoder, allowing model-specific encoding configuration to alter or break every collection's `toJson()` result.

## Fix Focus Areas
- src/collections/src/Traits/EnumeratesValues.php[17-17]
- src/collections/src/Traits/EnumeratesValues.php[967-969]

## Recommended Fix
Remove the Eloquent cast encoder from collection serialization and use native `json_encode` with the supplied options plus `JSON_THROW_ON_ERROR`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Cast encoder can break collections

If an application configures Eloquent’s JSON cast encoder and it returns false to signal an encoding failure, this call passes that result into toJson(): string. Collection serialization then throws a TypeError instead of retaining its previous JSON-string or JsonException behavior. The configured encoder also applies to collections even though it was set for Eloquent casts.

Fix in Claude Code Fix in Codex

}

/**
Expand Down
Loading