Skip to content

Commit da677dc

Browse files
committed
Improve attribute class
1 parent a782e34 commit da677dc

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Lodash/Testing/Attributes.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
class Attributes implements Arrayable
1616
{
17-
private const RELATION_MARKER = 'relations:';
17+
private const string RELATION_MARKER = 'relations:';
18+
private const string DYNAMIC_COUNT_MARKER = '*';
1819
private array $params;
1920
private array $attributes = [];
2021
/** @var array<self> */
@@ -97,7 +98,7 @@ private function parseParameters(array $params): void
9798
$attributes = [];
9899
$relations = [];
99100
foreach ($params as $key => $data) {
100-
if (str_starts_with($key, self::RELATION_MARKER)) {
101+
if (str_starts_with((string) $key, self::RELATION_MARKER)) {
101102
$ex = explode(':', $key);
102103
if (! isset($ex[1])) {
103104
throw new InvalidArgumentException('Relation is empty');
@@ -106,9 +107,9 @@ private function parseParameters(array $params): void
106107
$relName = $ex[1];
107108
$count = 1;
108109
if (isset($ex[2])) {
109-
$count = (int) $ex[2];
110+
$count = $ex[2] === self::DYNAMIC_COUNT_MARKER ? count($data) : (int) $ex[2];
110111
}
111-
$attrs = $params[$key];
112+
$attrs = $data;
112113

113114
$relations[$relName] = new self($attrs, $relName, $count);
114115
} else {

0 commit comments

Comments
 (0)