From bb87abe658cbc2dff5f06f58a01b0a35a17f1e25 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Fri, 11 Jul 2025 19:55:54 +0200 Subject: [PATCH 1/2] Adapt phpstan baseline to 3.x-dev, fix unignorable errors --- phpstan-baseline.neon | 15 +++++++++++++++ src/DataObject.php | 8 ++++---- src/DataSet.php | 26 +++++++++++++------------- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c513740f..c6b59f3c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -10,6 +10,21 @@ parameters: count: 1 path: src/DataSet.php + - + message: "#^Method Joomla\\\\Data\\\\DataSet\\:\\:valid\\(\\) with return type void returns false but should not return anything\\.$#" + count: 1 + path: src/DataSet.php + + - + message: "#^Method Joomla\\\\Data\\\\DataSet\\:\\:valid\\(\\) with return type void returns true but should not return anything\\.$#" + count: 1 + path: src/DataSet.php + + - + message: "#^PHPDoc tag @return with type bool is incompatible with native type void\\.$#" + count: 1 + path: src/DataSet.php + - message: "#^Property Joomla\\\\Data\\\\DataSet\\:\\:\\$current \\(int\\) does not accept default value of type false\\.$#" count: 1 diff --git a/src/DataObject.php b/src/DataObject.php index 1f3317ed..34a0f16d 100644 --- a/src/DataObject.php +++ b/src/DataObject.php @@ -198,7 +198,7 @@ public function dump($depth = 3, ?\SplObjectStorage $dumped = null) * @see IteratorAggregate::getIterator() * @since 1.0 */ - public function getIterator() + public function getIterator(): \ArrayIterator { return new \ArrayIterator($this->dump(0)); } @@ -206,11 +206,11 @@ public function getIterator() /** * Gets the data properties in a form that can be serialised to JSON format. * - * @return mixed + * @return \stdClass * * @since 1.0 */ - public function jsonSerialize() + public function jsonSerialize(): \stdClass { return $this->dump(); } @@ -304,7 +304,7 @@ protected function setProperty($property, $value) * * @since 1.0 */ - public function count() + public function count(): int { return \count($this->properties); } diff --git a/src/DataSet.php b/src/DataSet.php index 95d97e85..9a3d6ec2 100644 --- a/src/DataSet.php +++ b/src/DataSet.php @@ -256,7 +256,7 @@ public function toArray($associative = true, ...$keys) * * @since 1.0 */ - public function count() + public function count(): int { return \count($this->objects); } @@ -268,7 +268,7 @@ public function count() * * @since 1.0 */ - public function clear() + public function clear(): DataSet { $this->objects = []; $this->rewind(); @@ -279,11 +279,11 @@ public function clear() /** * Get the current data object in the set. * - * @return DataObject|false The current object, or false if the array is empty or the pointer is beyond the end of the elements. + * @return DataObject|bool The current object, or false if the array is empty or the pointer is beyond the end of the elements. * * @since 1.0 */ - public function current() + public function current(): DataObject|bool { return is_scalar($this->current) ? $this->objects[$this->current] : false; } @@ -350,11 +350,11 @@ public function jsonSerialize() /** * Gets the key of the current object in the iterator. * - * @return integer|false The object key on success; false on failure. + * @return int|bool|null The object key on success; false on failure. * * @since 1.0 */ - public function key() + public function key(): int|bool|null { return $this->current; } @@ -397,7 +397,7 @@ public function walk(callable $funcname) * * @since 1.0 */ - public function next() + public function next(): void { // Get the object offsets. $keys = $this->keys(); @@ -430,7 +430,7 @@ public function next() * * @since 1.0 */ - public function offsetExists($offset) + public function offsetExists($offset): bool { return isset($this->objects[$offset]); } @@ -444,7 +444,7 @@ public function offsetExists($offset) * * @since 1.0 */ - public function offsetGet($offset) + public function offsetGet($offset): DataObject|null { return $this->objects[$offset] ?? null; } @@ -460,7 +460,7 @@ public function offsetGet($offset) * @since 1.0 * @throws \InvalidArgumentException if an object is not an instance of DataObject. */ - public function offsetSet($offset, $object) + public function offsetSet($offset, $object): void { if (!($object instanceof DataObject)) { throw new \InvalidArgumentException( @@ -489,7 +489,7 @@ public function offsetSet($offset, $object) * * @since 1.0 */ - public function offsetUnset($offset) + public function offsetUnset($offset): void { if (!isset($this[$offset])) { // Do nothing if the offset does not exist. @@ -522,7 +522,7 @@ public function offsetUnset($offset) * * @since 1.0 */ - public function rewind() + public function rewind(): void { // Set the current position to the first object. if (empty($this->objects)) { @@ -540,7 +540,7 @@ public function rewind() * * @since 1.0 */ - public function valid() + public function valid(): void { // Check the current position. if (!is_scalar($this->current) || !isset($this->objects[$this->current])) { From 057a9ec44e963872880975d3c70b4b599c93fa45 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Fri, 11 Jul 2025 20:18:39 +0200 Subject: [PATCH 2/2] Fix wrong return type from previous commit --- phpstan-baseline.neon | 15 --------------- src/DataSet.php | 2 +- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c6b59f3c..c513740f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -10,21 +10,6 @@ parameters: count: 1 path: src/DataSet.php - - - message: "#^Method Joomla\\\\Data\\\\DataSet\\:\\:valid\\(\\) with return type void returns false but should not return anything\\.$#" - count: 1 - path: src/DataSet.php - - - - message: "#^Method Joomla\\\\Data\\\\DataSet\\:\\:valid\\(\\) with return type void returns true but should not return anything\\.$#" - count: 1 - path: src/DataSet.php - - - - message: "#^PHPDoc tag @return with type bool is incompatible with native type void\\.$#" - count: 1 - path: src/DataSet.php - - message: "#^Property Joomla\\\\Data\\\\DataSet\\:\\:\\$current \\(int\\) does not accept default value of type false\\.$#" count: 1 diff --git a/src/DataSet.php b/src/DataSet.php index 9a3d6ec2..5b48b09c 100644 --- a/src/DataSet.php +++ b/src/DataSet.php @@ -540,7 +540,7 @@ public function rewind(): void * * @since 1.0 */ - public function valid(): void + public function valid(): bool { // Check the current position. if (!is_scalar($this->current) || !isset($this->objects[$this->current])) {