Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.

Commit 1263bfd

Browse files
committed
Added metadata in interaction
1 parent 26ddecc commit 1263bfd

File tree

2 files changed

+17
-26
lines changed

2 files changed

+17
-26
lines changed

Tests/User/InteractionTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ public function testHttpTransport()
3434
$interaction = new Interaction(
3535
new User('123', ['a' => 1]),
3636
new ItemUUID('abc', 'article'),
37-
'buy',
38-
10
37+
'buy'
3938
);
4039

4140
$this->assertEquals(
@@ -46,7 +45,7 @@ public function testHttpTransport()
4645
$this->assertEquals('123', $interaction->getUser()->getId());
4746
$this->assertEquals('abc', $interaction->getItemUUID()->getId());
4847
$this->assertEquals('buy', $interaction->getEventName());
49-
$this->assertEquals(10, $interaction->getWeight());
48+
$this->assertEquals([], $interaction->getMetadata());
5049
}
5150

5251
/**
@@ -57,13 +56,14 @@ public function testHttpTransportDefaults()
5756
$interaction = new Interaction(
5857
new User('123', ['a' => 1]),
5958
new ItemUUID('abc', 'article'),
60-
'buy'
59+
'buy',
60+
['field' => 'value']
6161
);
6262

6363
$this->assertEquals(
6464
$interaction,
6565
HttpHelper::emulateHttpTransport($interaction)
6666
);
67-
$this->assertEquals(Interaction::NO_WEIGHT, $interaction->getWeight());
67+
$this->assertEquals(['field' => 'value'], $interaction->getMetadata());
6868
}
6969
}

User/Interaction.php

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@
2525
*/
2626
class Interaction implements HttpTransportable
2727
{
28-
/**
29-
* @var int
30-
*
31-
* No weight
32-
*/
33-
const NO_WEIGHT = 0;
34-
3528
/**
3629
* @var User
3730
*
@@ -54,30 +47,30 @@ class Interaction implements HttpTransportable
5447
private $eventName;
5548

5649
/**
57-
* @var int
50+
* @var array
5851
*
59-
* Weight
52+
* Metadata
6053
*/
61-
private $weight;
54+
private $metadata;
6255

6356
/**
6457
* Interaction constructor.
6558
*
6659
* @param User $user
6760
* @param ItemUUID $itemUUID
6861
* @param string $eventName
69-
* @param $weight
62+
* @param array $metadata
7063
*/
7164
public function __construct(
7265
User $user,
7366
ItemUUID $itemUUID,
7467
string $eventName,
75-
int $weight = self::NO_WEIGHT
68+
array $metadata = []
7669
) {
7770
$this->user = $user;
7871
$this->itemUUID = $itemUUID;
7972
$this->eventName = $eventName;
80-
$this->weight = $weight;
73+
$this->metadata = $metadata;
8174
}
8275

8376
/**
@@ -111,13 +104,13 @@ public function getEventName(): string
111104
}
112105

113106
/**
114-
* Get Weight.
107+
* Get Metadata.
115108
*
116-
* @return int
109+
* @return array
117110
*/
118-
public function getWeight(): int
111+
public function getMetadata(): array
119112
{
120-
return $this->weight;
113+
return $this->metadata;
121114
}
122115

123116
/**
@@ -131,9 +124,7 @@ public function toArray(): array
131124
'user' => $this->user->toArray(),
132125
'item_uuid' => $this->itemUUID->toArray(),
133126
'event_name' => $this->eventName,
134-
'weight' => self::NO_WEIGHT === $this->weight
135-
? false
136-
: $this->weight,
127+
'metadata' => $this->metadata,
137128
]);
138129
}
139130

@@ -152,7 +143,7 @@ public static function createFromArray(array $array)
152143
User::createFromArray($array['user']),
153144
ItemUUID::createFromArray($array['item_uuid']),
154145
(string) $array['event_name'],
155-
(int) ($array['weight'] ?? self::NO_WEIGHT)
146+
$array['metadata'] ?? []
156147
);
157148
}
158149
}

0 commit comments

Comments
 (0)