Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix collections property name conflict in Collections class #79

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 10 additions & 10 deletions src/Aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Aliases implements \ArrayAccess
/**
* @var array
*/
private array $aliases = [];
private array $typesenseAliases = [];

/**
* Aliases constructor.
Expand Down Expand Up @@ -78,46 +78,46 @@ public function __get($name)
return $this->{$name};
}

if (!isset($this->aliases[$name])) {
$this->aliases[$name] = new Alias($name, $this->apiCall);
if (!isset($this->typesenseAliases[$name])) {
$this->typesenseAliases[$name] = new Alias($name, $this->apiCall);
}

return $this->aliases[$name];
return $this->typesenseAliases[$name];
}

/**
* @inheritDoc
*/
public function offsetExists($offset): bool
{
return isset($this->aliases[$offset]);
return isset($this->typesenseAliases[$offset]);
}

/**
* @inheritDoc
*/
public function offsetGet($offset): Alias
{
if (!isset($this->aliases[$offset])) {
$this->aliases[$offset] = new Alias($offset, $this->apiCall);
if (!isset($this->typesenseAliases[$offset])) {
$this->typesenseAliases[$offset] = new Alias($offset, $this->apiCall);
}

return $this->aliases[$offset];
return $this->typesenseAliases[$offset];
}

/**
* @inheritDoc
*/
public function offsetSet($offset, $value): void
{
$this->aliases[$offset] = $value;
$this->typesenseAliases[$offset] = $value;
}

/**
* @inheritDoc
*/
public function offsetUnset($offset): void
{
unset($this->aliases[$offset]);
unset($this->typesenseAliases[$offset]);
}
}
20 changes: 10 additions & 10 deletions src/Collections.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Collections implements \ArrayAccess
/**
* @var array
*/
private array $collections = [];
private array $typesenseCollections = [];

/**
* Collections constructor.
Expand All @@ -46,11 +46,11 @@ public function __get($collectionName)
if (isset($this->{$collectionName})) {
return $this->{$collectionName};
}
if (!isset($this->collections[$collectionName])) {
$this->collections[$collectionName] = new Collection($collectionName, $this->apiCall);
if (!isset($this->typesenseCollections[$collectionName])) {
$this->typesenseCollections[$collectionName] = new Collection($collectionName, $this->apiCall);
}

return $this->collections[$collectionName];
return $this->typesenseCollections[$collectionName];
}

/**
Expand Down Expand Up @@ -79,34 +79,34 @@ public function retrieve(): array
*/
public function offsetExists($offset): bool
{
return isset($this->collections[$offset]);
return isset($this->typesenseCollections[$offset]);
}

/**
* @inheritDoc
*/
public function offsetGet($offset): Collection
{
if (!isset($this->collections[$offset])) {
$this->collections[$offset] = new Collection($offset, $this->apiCall);
if (!isset($this->typesenseCollections[$offset])) {
$this->typesenseCollections[$offset] = new Collection($offset, $this->apiCall);
}

return $this->collections[$offset];
return $this->typesenseCollections[$offset];
}

/**
* @inheritDoc
*/
public function offsetSet($offset, $value): void
{
$this->collections[$offset] = $value;
$this->typesenseCollections[$offset] = $value;
}

/**
* @inheritDoc
*/
public function offsetUnset($offset): void
{
unset($this->collections[$offset]);
unset($this->typesenseCollections[$offset]);
}
}
20 changes: 10 additions & 10 deletions src/ConversationModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ConversationModels implements \ArrayAccess
/**
* @var array
*/
private array $models = [];
private array $typesenseModels = [];

/**
* ConversationModels constructor.
Expand All @@ -44,11 +44,11 @@ public function __get($id)
if (isset($this->{$id})) {
return $this->{$id};
}
if (!isset($this->models[$id])) {
$this->models[$id] = new ConversationModel($id, $this->apiCall);
if (!isset($this->typesenseModels[$id])) {
$this->typesenseModels[$id] = new ConversationModel($id, $this->apiCall);
}

return $this->models[$id];
return $this->typesenseModels[$id];
}

/**
Expand Down Expand Up @@ -76,34 +76,34 @@ public function retrieve(): array
*/
public function offsetExists($offset): bool
{
return isset($this->models[$offset]);
return isset($this->typesenseModels[$offset]);
}

/**
* @inheritDoc
*/
public function offsetGet($offset): ConversationModel
{
if (!isset($this->models[$offset])) {
$this->models[$offset] = new ConversationModel($offset, $this->apiCall);
if (!isset($this->typesenseModels[$offset])) {
$this->typesenseModels[$offset] = new ConversationModel($offset, $this->apiCall);
}

return $this->models[$offset];
return $this->typesenseModels[$offset];
}

/**
* @inheritDoc
*/
public function offsetSet($offset, $value): void
{
$this->models[$offset] = $value;
$this->typesenseModels[$offset] = $value;
}

/**
* @inheritDoc
*/
public function offsetUnset($offset): void
{
unset($this->models[$offset]);
unset($this->typesenseModels[$offset]);
}
}
6 changes: 3 additions & 3 deletions src/Conversations.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Conversations implements \ArrayAccess
/**
* @var ConversationModels
*/
public ConversationModels $models;
public ConversationModels $typesenseModels;

/**
* @var ApiCall
Expand All @@ -34,7 +34,7 @@ class Conversations implements \ArrayAccess
public function __construct(ApiCall $apiCall)
{
$this->apiCall = $apiCall;
$this->models = new ConversationModels($this->apiCall);
$this->typesenseModels = new ConversationModels($this->apiCall);
}

/**
Expand All @@ -51,7 +51,7 @@ public function retrieve(): array
*/
public function getModels(): ConversationModels
{
return $this->models;
return $this->typesenseModels;
}

/**
Expand Down
20 changes: 10 additions & 10 deletions src/Presets.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Presets implements \ArrayAccess
/**
* @var array
*/
private array $presets = [];
private array $typesensePresets = [];

/**
* Presets constructor.
Expand Down Expand Up @@ -107,46 +107,46 @@ public function __get($presetName)
if (isset($this->{$presetName})) {
return $this->{$presetName};
}
if (!isset($this->presets[$presetName])) {
$this->presets[$presetName] = new Preset($presetName, $this->apiCall);
if (!isset($this->typesensePresets[$presetName])) {
$this->typesensePresets[$presetName] = new Preset($presetName, $this->apiCall);
}

return $this->presets[$presetName];
return $this->typesensePresets[$presetName];
}

/**
* @inheritDoc
*/
public function offsetExists($offset): bool
{
return isset($this->presets[$offset]);
return isset($this->typesensePresets[$offset]);
}

/**
* @inheritDoc
*/
public function offsetGet($offset): Preset
{
if (!isset($this->presets[$offset])) {
$this->presets[$offset] = new Preset($offset, $this->apiCall);
if (!isset($this->typesensePresets[$offset])) {
$this->typesensePresets[$offset] = new Preset($offset, $this->apiCall);
}

return $this->presets[$offset];
return $this->typesensePresets[$offset];
}

/**
* @inheritDoc
*/
public function offsetSet($offset, $value): void
{
$this->presets[$offset] = $value;
$this->typesensePresets[$offset] = $value;
}

/**
* @inheritDoc
*/
public function offsetUnset($offset): void
{
unset($this->presets[$offset]);
unset($this->typesensePresets[$offset]);
}
}
6 changes: 3 additions & 3 deletions tests/Feature/ConversationModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function testCanGetAModelById(): void
{
$this->mockApiCall()->allows()->get($this->endPointPath(), [])->andReturns([]);

$response = $this->mockConversations()->models[$this->id]->retrieve();
$response = $this->mockConversations()->typesenseModels[$this->id]->retrieve();
$this->assertEquals([], $response);
}

Expand All @@ -24,15 +24,15 @@ public function testCanUpdateAModelById(): void
];
$this->mockApiCall()->allows()->put($this->endPointPath(), $data)->andReturns([]);

$response = $this->mockConversations()->models[$this->id]->update($data);
$response = $this->mockConversations()->typesenseModels[$this->id]->update($data);
$this->assertEquals([], $response);
}

public function testCanDeleteAModelById(): void
{
$this->mockApiCall()->allows()->delete($this->endPointPath())->andReturns([]);

$response = $this->mockConversations()->models[$this->id]->delete();
$response = $this->mockConversations()->typesenseModels[$this->id]->delete();
$this->assertEquals([], $response);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/ConversationModelsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ public function testCanCreateAModel(): void

$this->mockApiCall()->allows()->post(static::RESOURCE_PATH, $data)->andReturns([]);

$response = $this->mockConversations()->models->create($data);
$response = $this->mockConversations()->typesenseModels->create($data);
$this->assertEquals([], $response);
}

public function testCanRetrieveAllModels(): void
{
$this->mockApiCall()->allows()->get(static::RESOURCE_PATH, [])->andReturns([]);
$this->mockConversations()->models->retrieve();
$this->mockConversations()->typesenseModels->retrieve();

$response = $this->client()->conversations->models->retrieve();
$response = $this->client()->conversations->typesenseModels->retrieve();
$this->assertEquals([], $response);
}
}