Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions Tests/User/InteractionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public function testHttpTransport()
$interaction = new Interaction(
new User('123', ['a' => 1]),
new ItemUUID('abc', 'article'),
'buy',
10
'buy'
);

$this->assertEquals(
Expand All @@ -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());
}

/**
Expand All @@ -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());
}
}
33 changes: 12 additions & 21 deletions User/Interaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@
*/
class Interaction implements HttpTransportable
{
/**
* @var int
*
* No weight
*/
const NO_WEIGHT = 0;

/**
* @var User
*
Expand All @@ -54,30 +47,30 @@ class Interaction implements HttpTransportable
private $eventName;

/**
* @var int
* @var array
*
* Weight
* Metadata
*/
private $weight;
private $metadata;

/**
* Interaction constructor.
*
* @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;
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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,
]);
}

Expand All @@ -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'] ?? []
);
}
}