diff --git a/Tests/User/InteractionTest.php b/Tests/User/InteractionTest.php index d16f37f..0623149 100644 --- a/Tests/User/InteractionTest.php +++ b/Tests/User/InteractionTest.php @@ -34,8 +34,7 @@ public function testHttpTransport() $interaction = new Interaction( new User('123', ['a' => 1]), new ItemUUID('abc', 'article'), - 'buy', - 10 + 'buy' ); $this->assertEquals( @@ -46,7 +45,7 @@ public function testHttpTransport() $this->assertEquals('123', $interaction->getUser()->getId()); $this->assertEquals('abc', $interaction->getItemUUID()->getId()); $this->assertEquals('buy', $interaction->getEventName()); - $this->assertEquals(10, $interaction->getWeight()); + $this->assertEquals([], $interaction->getMetadata()); } /** @@ -57,13 +56,14 @@ public function testHttpTransportDefaults() $interaction = new Interaction( new User('123', ['a' => 1]), new ItemUUID('abc', 'article'), - 'buy' + 'buy', + ['field' => 'value'] ); $this->assertEquals( $interaction, HttpHelper::emulateHttpTransport($interaction) ); - $this->assertEquals(Interaction::NO_WEIGHT, $interaction->getWeight()); + $this->assertEquals(['field' => 'value'], $interaction->getMetadata()); } } diff --git a/User/Interaction.php b/User/Interaction.php index d037532..9d15d48 100644 --- a/User/Interaction.php +++ b/User/Interaction.php @@ -25,13 +25,6 @@ */ class Interaction implements HttpTransportable { - /** - * @var int - * - * No weight - */ - const NO_WEIGHT = 0; - /** * @var User * @@ -54,11 +47,11 @@ class Interaction implements HttpTransportable private $eventName; /** - * @var int + * @var array * - * Weight + * Metadata */ - private $weight; + private $metadata; /** * Interaction constructor. @@ -66,18 +59,18 @@ class Interaction implements HttpTransportable * @param User $user * @param ItemUUID $itemUUID * @param string $eventName - * @param $weight + * @param array $metadata */ public function __construct( User $user, ItemUUID $itemUUID, string $eventName, - int $weight = self::NO_WEIGHT + array $metadata = [] ) { $this->user = $user; $this->itemUUID = $itemUUID; $this->eventName = $eventName; - $this->weight = $weight; + $this->metadata = $metadata; } /** @@ -111,13 +104,13 @@ public function getEventName(): string } /** - * Get Weight. + * Get Metadata. * - * @return int + * @return array */ - public function getWeight(): int + public function getMetadata(): array { - return $this->weight; + return $this->metadata; } /** @@ -131,9 +124,7 @@ public function toArray(): array 'user' => $this->user->toArray(), 'item_uuid' => $this->itemUUID->toArray(), 'event_name' => $this->eventName, - 'weight' => self::NO_WEIGHT === $this->weight - ? false - : $this->weight, + 'metadata' => $this->metadata, ]); } @@ -152,7 +143,7 @@ public static function createFromArray(array $array) User::createFromArray($array['user']), ItemUUID::createFromArray($array['item_uuid']), (string) $array['event_name'], - (int) ($array['weight'] ?? self::NO_WEIGHT) + $array['metadata'] ?? [] ); } }