Skip to content

Commit

Permalink
codereview
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubTesarek committed Apr 24, 2020
1 parent 1d6807f commit 25bdd69
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 29 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# PHP API Client for Matej recommendation engine

[![Latest Stable Version](https://img.shields.io/packagist/v/lmc/matej-client.svg?style=flat-square)](https://packagist.org/packages/lmc/matej-client)
Expand Down
26 changes: 13 additions & 13 deletions UPGRADE-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ $recommendation = UserRecommendation::create('user-id', 5, 'scenario', 1.0, 3600
#### After
```php
$recommendation = UserRecommendation::create('user-id', 'scenario')
->setCount(5)
->setRotationRate(1.0)
->setRotationTime(3600);
->setCount(5)
->setRotationRate(1.0)
->setRotationTime(3600);
```

which is equivalent to
Expand All @@ -49,18 +49,18 @@ We replaced them with constructors for creating Interaction based on `$itemId` o

```php
Interaction::withItem(
string $interactionType,
string $userId,
string $itemId,
int $timestamp = null
string $interactionType,
string $userId,
string $itemId,
int $timestamp = null
```

```php
Interaction::withAliasedItem(
string $interactionType,
string $userId,
array $itemIdAlias,
int $timestamp = null):
string $interactionType,
string $userId,
array $itemIdAlias,
int $timestamp = null):
```

The first argument is always a string representing interaction type. Consult the table bellow to find out the correct value to fill in:
Expand Down Expand Up @@ -89,7 +89,7 @@ $interaction = Interaction::withItem('bookmarks', 'user-id', 'item_id', time());
Interactions now support custom attributes. These can be added using fluent API
methods `setAttribute()` and `setAttributes()`.

Argument `value` was removed from constructor methods and has to be set using new attribute methods. Its real name might have change as well. For example, for interaction type `bookmarks`, it was renamed to `stars`.
Argument `value` was removed from constructor methods and has to be set using new attribute methods. Its real name might have change as well. For example, for interaction type `ratings`, it was renamed to `stars`.

**Attribute `context` is no longer supported and was removed.**

Expand All @@ -101,7 +101,7 @@ $interaction = Interaction::rating('user-id', 'item_id', 0.5);
#### After
```php
$interaction = Interaction::create('ratings', 'user-id', 'item_id')
->setAttribute('stars', 0.5)
->setAttribute('stars', 0.5)
```

which is equivalent to
Expand Down
9 changes: 2 additions & 7 deletions src/Model/Command/Interaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@ public static function withAliasedItem(
string $itemId,
int $timestamp = null
): self {
$interaction = new static(
return new static(
$interactionType, $userId, $itemIdAlias, $itemId, $timestamp
);

return $interaction;
}

public function getUserId(): string
Expand Down Expand Up @@ -114,16 +112,13 @@ public function setAttribute(string $name, $value): self

public function getCommandParameters(): array
{
$common = [
return [
'interaction_type' => $this->interactionType,
'user_id' => $this->userId,
'timestamp' => $this->timestamp,
'attributes' => $this->attributes,
$this->itemIdAlias => $this->itemId,
];
$common[$this->itemIdAlias] = $this->itemId;

return $common;
}

protected function setInteractionType(string $interactionType): void
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/Model/Command/InteractionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public function initTimeMock(): void
*/
public function shouldRaiseExceptionWithInvalidAttributeName(): void
{
$command = Interaction::withItem('bookmarks', 'user-id', 'item-id');
$this->expectException(DomainException::class);
$this->expectExceptionMessage(
'Value "invalid^*!@" does not match type identifier format requirement (must contain only of alphanumeric chars, dash or underscore)');
$command = Interaction::withItem('bookmarks', 'user-id', 'item-id');
'invalid^*!@" does not match type identifier format requirement');
$command->setAttribute('invalid^*!@', 'value');
}

Expand All @@ -37,10 +37,10 @@ public function shouldRaiseExceptionWithInvalidAttributeName(): void
*/
public function shouldRaiseExceptionWithInvalidAttributeNameInBatch(): void
{
$command = Interaction::withItem('bookmarks', 'user-id', 'item-id');
$this->expectException(DomainException::class);
$this->expectExceptionMessage(
'Value "invalid^*!@" does not match type identifier format requirement (must contain only of alphanumeric chars, dash or underscore)');
$command = Interaction::withItem('bookmarks', 'user-id', 'item-id');
'"invalid^*!@" does not match type identifier format requirement');
$command->setAttributes([
'valid' => 'value1',
'invalid^*!@' => 'value2',
Expand All @@ -54,7 +54,7 @@ public function shouldRaiseExceptionWithInvalidInteractionType(): void
{
$this->expectException(DomainException::class);
$this->expectExceptionMessage(
'Value "invalid^*!@" does not match type identifier format requirement (must contain only of alphanumeric chars, dash or underscore)');
'"invalid^*!@" does not match type identifier format requirement');
$command = Interaction::withItem('invalid^*!@', 'user-id', 'item-id');
}

Expand All @@ -65,7 +65,7 @@ public function shouldRaiseExceptionWithInvalidUserId(): void
{
$this->expectException(DomainException::class);
$this->expectExceptionMessage(
'Value "invalid^*!@" does not match type identifier format requirement (must contain only of alphanumeric chars, dash or underscore)');
'"invalid^*!@" does not match type identifier format requirement');
$command = Interaction::withItem('bookmarks', 'invalid^*!@', 'item-id');
}

Expand All @@ -76,7 +76,7 @@ public function shouldRaiseExceptionWithInvalidItemId(): void
{
$this->expectException(DomainException::class);
$this->expectExceptionMessage(
'Value "invalid^*!@" does not match type identifier format requirement (must contain only of alphanumeric chars, dash or underscore)');
'"invalid^*!@" does not match type identifier format requirement');
$command = Interaction::withItem('bookmarks', 'user-id', 'invalid^*!@');
}

Expand All @@ -87,7 +87,7 @@ public function shouldRaiseExceptionWithInvalidItemIdAliasName(): void
{
$this->expectException(DomainException::class);
$this->expectExceptionMessage(
'Value "invalid^*!@" does not match type identifier format requirement (must contain only of alphanumeric chars, dash or underscore)');
'"invalid^*!@" does not match type identifier format requirement');
$command = Interaction::withAliasedItem('bookmarks', 'user-id', 'invalid^*!@', 'item-id');
}

Expand Down

0 comments on commit 25bdd69

Please sign in to comment.