Skip to content

Commit

Permalink
Remove queue service and rename responses
Browse files Browse the repository at this point in the history
  • Loading branch information
tmekinyan committed Feb 16, 2020
1 parent 36b0953 commit aab263e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 45 deletions.
31 changes: 15 additions & 16 deletions src/Couchbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ class Couchbase
private $queryBuilder;
/** @var QueryFilters */
private $queryFilters;
/** @var Queue */
private $queue;
/** @var Mutations */
private $mutations;
/** @var Response */
private $response;
/** @var Responses */
private $responses;
/** @var Metrics */
private $metrics;

/** @var mixed[] */
private $queue = [];

/** @var Bucket[] */
private $buckets = [];

Expand All @@ -34,17 +35,15 @@ class Couchbase
* @param QueryBuilder $queryBuilder
* @param QueryFilters $queryFilters
* @param Mutations $mutations
* @param Queue $queue
* @param Response $response
* @param Responses $responses
* @param Metrics $metrics
*/
public function __construct(QueryBuilder $queryBuilder, QueryFilters $queryFilters, Mutations $mutations, Queue $queue, Response $response, Metrics $metrics)
public function __construct(QueryBuilder $queryBuilder, QueryFilters $queryFilters, Mutations $mutations, Responses $responses, Metrics $metrics)
{
$this->queryBuilder = $queryBuilder;
$this->queryFilters = $queryFilters;
$this->mutations = $mutations;
$this->queue = $queue;
$this->response = $response;
$this->responses = $responses;
$this->metrics = $metrics;
}

Expand Down Expand Up @@ -112,7 +111,7 @@ public function getPart(string $cbId, array $paths)

$response = $lookupInBuilder->execute();

return $this->response->formatFragment($response, $paths);
return $this->responses->formatFragment($response, $paths);
}

/**
Expand All @@ -125,7 +124,7 @@ public function get(array $cbId, bool $uniqueResultDirectReturn = true)
{
$response = $this->bucket->get($cbId); //return an array with the data in "value" key

$formatted = $this->response->format($response); //There is always one element in $return (can be null)
$formatted = $this->responses->format($response); //There is always one element in $return (can be null)

return ($uniqueResultDirectReturn && count($formatted) === 1) ? $formatted[0] : $formatted;
}
Expand Down Expand Up @@ -168,17 +167,17 @@ public function setPart(string $cbId, array $mutation): void
*/
public function queue($model): bool
{
return $this->queue->add($model);
$this->queue[] = $model;

return true;
}

/**
* @return bool
*/
public function commitQueue(): bool
{
$models = $this->queue->getUncommitted();

foreach ($models as $model) {
foreach ($this->queue as $model) {
$this->set($model->cbId, $model);
}

Expand Down Expand Up @@ -215,7 +214,7 @@ public function counter(string $cbId, int $amount, int $initial = 0): int
{
$response = $this->bucket->counter($cbId, $amount, ['initial' => $initial]);

return (int) $this->response->formatDocument($response);
return (int) $this->responses->formatDocument($response);
}

/**
Expand Down
27 changes: 0 additions & 27 deletions src/Queue.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/Response.php → src/Responses.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use stdClass;

class Response
class Responses
{
/**
* @param array $documents
Expand Down Expand Up @@ -53,4 +53,4 @@ public function formatFragment(DocumentFragment $documentFragment, array $paths)

return $return;
}
}
}

0 comments on commit aab263e

Please sign in to comment.