Skip to content

Commit

Permalink
Dataset: adjust to rdf-interface 1.0.0; composer.json: bump rdf-inter…
Browse files Browse the repository at this point in the history
…face ecosystem to ^1.0.0
  • Loading branch information
zozlak committed Nov 1, 2022
1 parent 87b84b3 commit 36785b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"require": {
"php": ">=8.0",
"zozlak/rdf-constants": "^1.1",
"sweetrdf/rdf-interface": "^1.0.0-RC1",
"sweetrdf/rdf-helpers": "^1.0.0-RC1"
"sweetrdf/rdf-interface": "^1.0.0",
"sweetrdf/rdf-helpers": "^1.0.0"
},
"suggest": {
"sweetrdf/quick-rdf-io": "*"
Expand All @@ -32,8 +32,8 @@
"phpstan/phpstan": "*",
"squizlabs/php_codesniffer": "*",
"php-coveralls/php-coveralls": "^2.4",
"sweetrdf/rdf-interface-tests": "^1.0.0-RC1",
"sweetrdf/term-templates": "^1.0.0-RC1"
"sweetrdf/rdf-interface-tests": "^1.0.0",
"sweetrdf/term-templates": "^1.0.0"
},
"autoload-dev": {
"psr-4": {
Expand Down
25 changes: 12 additions & 13 deletions src/simpleRdf/Dataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,14 @@ public function count(): int {

/**
*
* @param iQuad|iQuadCompare|callable $offset
* @param iQuad|iQuadCompare|callable|int<0, 0> $offset
* @return bool
*/
public function offsetExists($offset): bool {
return $this->exists($offset);
}

private function exists(iQuadCompare | callable $offset): bool {
private function exists(iQuadCompare | callable | int $offset): bool {
try {
$iter = $this->findMatchingQuads($offset);
$this->checkIteratorEnd($iter);
Expand All @@ -225,15 +225,6 @@ public function offsetGet($offset): iQuad {
* @throws OutOfBoundsException
*/
private function get(iQuadCompare | callable | int $offset): iQuad {
if (is_int($offset)) {
if ($offset !== 0) {
throw new OutOfBoundsException("Only integer offset of 0 is allowed");
}
if (count($this->quads) === 0) {
throw new OutOfBoundsException("Dataset is empty");
}
return $this->quads[0];
}
$iter = $this->findMatchingQuads($offset);
$idx = $iter->current();
$this->checkIteratorEnd($iter);
Expand Down Expand Up @@ -409,8 +400,11 @@ private function listQuadElement(iQuadCompare | iQuadIterator | iQuadIteratorAgg
* @throws OutOfBoundsException
*/
private function findMatchingQuads(
iQuadCompare | iQuadIterator | iQuadIteratorAggregate | callable | null $offset
iQuadCompare | iQuadIterator | iQuadIteratorAggregate | callable | int | null $offset
): Generator {
if (is_int($offset) && $offset !== 0) {
throw new OutOfBoundsException("Only integer offset of 0 is allowed");
}
$fn = $this->prepareMatchFunction($offset ?? true);
$n = 0;
foreach ($this->quads as $i => $q) {
Expand Down Expand Up @@ -440,7 +434,7 @@ private function findNotMatchingQuads(
}
}

private function prepareMatchFunction(iQuadCompare | iQuadIterator | iQuadIteratorAggregate | callable | bool $offset): callable {
private function prepareMatchFunction(iQuadCompare | iQuadIterator | iQuadIteratorAggregate | callable | bool | int $offset): callable {
$fn = function () use ($offset) {
return $offset;
};
Expand All @@ -459,6 +453,11 @@ private function prepareMatchFunction(iQuadCompare | iQuadIterator | iQuadIterat
}
return false;
};
} elseif (is_int($offset)) {
$fn = function (iQuad $x): bool {
static $n = 0;
return $n++ === 0;
};
}
return $fn;
}
Expand Down

0 comments on commit 36785b3

Please sign in to comment.