diff --git a/composer.json b/composer.json index ab93233..2b127f7 100644 --- a/composer.json +++ b/composer.json @@ -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": "*" @@ -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": { diff --git a/src/simpleRdf/Dataset.php b/src/simpleRdf/Dataset.php index d1dec39..67bc473 100644 --- a/src/simpleRdf/Dataset.php +++ b/src/simpleRdf/Dataset.php @@ -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); @@ -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); @@ -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) { @@ -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; }; @@ -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; }