Skip to content
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
8 changes: 8 additions & 0 deletions src/DocumentStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,12 @@ public function filterDocs(string $collectionName, Filter $filter, int $skip = n
* @return array
*/
public function filterDocIds(string $collectionName, Filter $filter): array;

/**
* @param string $collectionName
* @param Filter $filter
* @return int The number of documents
* @throws UnknownCollection
*/
public function countDocs(string $collectionName, Filter $filter): int;
}
17 changes: 17 additions & 0 deletions src/InMemoryDocumentStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,4 +572,21 @@ private function isSequentialArray(array $array): bool

return \array_keys($array) === \range(0, \count($array) - 1);
}

/**
* @inheritDoc
*/
public function countDocs(string $collectionName, Filter $filter) : int
{
$this->assertHasCollection($collectionName);

$counter = 0;
foreach ($this->inMemoryConnection['documents'][$collectionName] as $docId => $doc) {
if ($filter->match($doc, $docId)) {
$counter++;
}
}

return $counter;
}
}