Update phpDoc for interface traits

This commit is contained in:
Sebastian Meyer 2024-02-11 19:07:05 +01:00
parent fec263c64b
commit 3610dccfc5
4 changed files with 60 additions and 31 deletions

View File

@ -28,6 +28,8 @@ use ArrayAccess;
/** /**
* A generic implementation of the ArrayAccess interface. * A generic implementation of the ArrayAccess interface.
* *
* Internally it accesses the protected `$_data` array.
*
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com> * @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
* @package Basics\InterfaceTraits * @package Basics\InterfaceTraits
* *
@ -42,9 +44,11 @@ trait ArrayAccessTrait
/** /**
* Holds the array-accessible data. * Holds the array-accessible data.
* *
* @var array<TValue> * @var TValue[]
*
* @internal
*/ */
protected array $data = []; protected array $_data = [];
/** /**
* Check if the specified offset exists. * Check if the specified offset exists.
@ -53,11 +57,11 @@ trait ArrayAccessTrait
* *
* @return bool Whether the offset exists * @return bool Whether the offset exists
* *
* @internal * @api
*/ */
public function offsetExists(mixed $offset): bool public function offsetExists(mixed $offset): bool
{ {
return isset($this->data[$offset]); return isset($this->_data[$offset]);
} }
/** /**
@ -67,11 +71,11 @@ trait ArrayAccessTrait
* *
* @return ?TValue The value at the offset or NULL if invalid * @return ?TValue The value at the offset or NULL if invalid
* *
* @internal * @api
*/ */
public function offsetGet(mixed $offset): mixed public function offsetGet(mixed $offset): mixed
{ {
return $this->data[$offset] ?? null; return $this->_data[$offset] ?? null;
} }
/** /**
@ -82,14 +86,14 @@ trait ArrayAccessTrait
* *
* @return void * @return void
* *
* @internal * @api
*/ */
public function offsetSet(mixed $offset, mixed $value): void public function offsetSet(mixed $offset, mixed $value): void
{ {
if (is_null($offset)) { if (is_null($offset)) {
$this->data[] = $value; $this->_data[] = $value;
} else { } else {
$this->data[$offset] = $value; $this->_data[$offset] = $value;
} }
} }
@ -100,10 +104,10 @@ trait ArrayAccessTrait
* *
* @return void * @return void
* *
* @internal * @api
*/ */
public function offsetUnset(mixed $offset): void public function offsetUnset(mixed $offset): void
{ {
unset($this->data[$offset]); unset($this->_data[$offset]);
} }
} }

View File

@ -28,12 +28,15 @@ use Countable;
/** /**
* A generic implementation of the Countable interface. * A generic implementation of the Countable interface.
* *
* Internally it counts the values of the protected `$_data` array.
*
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com> * @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
* @package Basics\InterfaceTraits * @package Basics\InterfaceTraits
* *
* @api * @api
* *
* @template TValue of mixed * @template TValue of mixed
* @implements Countable
* @phpstan-require-implements Countable * @phpstan-require-implements Countable
*/ */
trait CountableTrait trait CountableTrait
@ -41,19 +44,21 @@ trait CountableTrait
/** /**
* Holds the countable data. * Holds the countable data.
* *
* @var array<TValue> * @var TValue[]
*
* @internal
*/ */
protected array $data = []; protected array $_data = [];
/** /**
* Count the data items. * Count the data items.
* *
* @return int<0, max> The number of data items * @return int<0, max> The number of data items
* *
* @internal * @api
*/ */
public function count(): int public function count(): int
{ {
return count($this->data); return count($this->_data);
} }
} }

View File

@ -29,6 +29,8 @@ use IteratorAggregate;
/** /**
* A generic implementation of the IteratorAggregate interface. * A generic implementation of the IteratorAggregate interface.
* *
* Internally it iterates over the protected `$_data` array.
*
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com> * @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
* @package Basics\InterfaceTraits * @package Basics\InterfaceTraits
* *
@ -43,19 +45,21 @@ trait IteratorAggregateTrait
/** /**
* Holds the iterable data. * Holds the iterable data.
* *
* @var array<TValue> * @var TValue[]
*
* @internal
*/ */
protected array $data = []; protected array $_data = [];
/** /**
* Retrieve an external iterator. * Retrieve an external iterator.
* *
* @return ArrayIterator<array-key, TValue> New array iterator for data array * @return ArrayIterator<array-key, TValue> New iterator for the data array
* *
* @internal * @api
*/ */
public function getIterator(): ArrayIterator public function getIterator(): ArrayIterator
{ {
return new ArrayIterator($this->data); return new ArrayIterator($this->_data);
} }
} }

View File

@ -28,6 +28,8 @@ use Iterator;
/** /**
* A generic implementation of the Iterator interface. * A generic implementation of the Iterator interface.
* *
* Internally it iterates over the protected `$_data` array.
*
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com> * @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
* @package Basics\InterfaceTraits * @package Basics\InterfaceTraits
* *
@ -42,22 +44,24 @@ trait IteratorTrait
/** /**
* Holds the iterable data. * Holds the iterable data.
* *
* @var array<TValue> * @var TValue[]
*
* @internal
*/ */
protected array $data = []; protected array $_data = [];
/** /**
* Return the current item. * Return the current item.
* *
* @return ?TValue The current item or NULL if invalid * @return ?TValue The current item or NULL if invalid
* *
* @internal * @api
*/ */
public function current(): mixed public function current(): mixed
{ {
if ($this->valid()) { if ($this->valid()) {
/** @var TValue */ /** @var TValue */
return current($this->data); return current($this->_data);
} }
return null; return null;
} }
@ -67,11 +71,11 @@ trait IteratorTrait
* *
* @return ?array-key The current key or NULL if invalid * @return ?array-key The current key or NULL if invalid
* *
* @internal * @api
*/ */
public function key(): mixed public function key(): mixed
{ {
return key($this->data); return key($this->_data);
} }
/** /**
@ -79,11 +83,23 @@ trait IteratorTrait
* *
* @return void * @return void
* *
* @internal * @api
*/ */
public function next(): void public function next(): void
{ {
next($this->data); next($this->_data);
}
/**
* Move back to previous item.
*
* @return void
*
* @api
*/
public function prev(): void
{
prev($this->_data);
} }
/** /**
@ -91,11 +107,11 @@ trait IteratorTrait
* *
* @return void * @return void
* *
* @internal * @api
*/ */
public function rewind(): void public function rewind(): void
{ {
reset($this->data); reset($this->_data);
} }
/** /**
@ -103,7 +119,7 @@ trait IteratorTrait
* *
* @return bool Whether the current position is valid * @return bool Whether the current position is valid
* *
* @internal * @api
*/ */
public function valid(): bool public function valid(): bool
{ {