-
Notifications
You must be signed in to change notification settings - Fork 0
Dev #14
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
Dev #14
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,14 +52,14 @@ final class IndexedCollector implements CollectorInterface, \ArrayAccess, \Itera | |
| /** | ||
| * Index of values with keys of scalar type. | ||
| * | ||
| * @var array<TKey, list<TValue>> | ||
| * @var array<scalar, list<TValue>> | ||
| */ | ||
| private array $scalarIndex = []; | ||
|
|
||
| /** | ||
| * Index of values with keys of object type. | ||
| * | ||
| * @var \SplObjectStorage<TKey&object, list<TValue>> | ||
| * @var \SplObjectStorage<object, list<TValue>> | ||
| */ | ||
| private \SplObjectStorage $objectIndex; | ||
|
|
||
|
|
@@ -81,9 +81,9 @@ public function __construct( | |
| foreach ($this->source as $key => $value) { | ||
| $this->collected[] = [$key, $value]; | ||
|
|
||
| if (\is_string($key) || \is_int($key)) { | ||
| $this->scalarIndex[$key] = $this->scalarIndex[$key] ?? []; | ||
| $this->scalarIndex[$key][] = $value; | ||
| if (\is_scalar($key)) { | ||
| $this->scalarIndex[$key] = $this->scalarIndex[$key] ?? []; // @phpstan-ignore-line | ||
| $this->scalarIndex[$key][] = $value; // @phpstan-ignore-line | ||
|
Comment on lines
+84
to
+86
|
||
| continue; | ||
| } | ||
|
|
||
|
|
@@ -115,7 +115,7 @@ public function getIterator(): \Traversable | |
| public function offsetExists(mixed $offset): bool | ||
| { | ||
| return match (true) { | ||
| \is_string($offset) || \is_int($offset) => \array_key_exists($offset, $this->scalarIndex), | ||
| \is_scalar($offset) => \array_key_exists($offset, $this->scalarIndex), // @phpstan-ignore-line | ||
| \is_object($offset) => $this->objectIndex->contains($offset), | ||
| default => throw new UnsupportedException('Only object, string and integer keys are supported.'), | ||
|
||
| }; | ||
|
|
@@ -135,7 +135,7 @@ public function offsetGet(mixed $offset): mixed | |
| } | ||
|
|
||
| return match (true) { | ||
| \is_string($offset) || \is_int($offset) => $this->scalarIndex[$offset], | ||
| \is_scalar($offset) => $this->scalarIndex[$offset], // @phpstan-ignore-line | ||
| \is_object($offset) => $this->objectIndex[$offset], | ||
| default => throw new UnsupportedException('Only object, string and integer keys are supported.'), | ||
|
||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment "Currently, the allowed key types are scalar values (int, float, string, bool, null) and objects." is inconsistent with the error messages in the code (lines 98, 120, 140) which state "Only object, string and integer keys are supported." Since the code change now supports all scalar types, the error messages should be updated to match this documentation, or vice versa.