Skip to content

Commit

Permalink
ConfigObject: Document generics
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Feb 15, 2024
1 parent 58b3321 commit d6881e0
Show file tree
Hide file tree
Showing 2 changed files with 334 additions and 40 deletions.
24 changes: 14 additions & 10 deletions library/Icinga/Data/ConfigObject.php
Expand Up @@ -10,6 +10,10 @@

/**
* Container for configuration values
*
* @template TValue
* @implements Iterator<string, TValue>
* @implements ArrayAccess<string, TValue>
*/
class ConfigObject extends ArrayDatasource implements Iterator, ArrayAccess
{
Expand Down Expand Up @@ -60,7 +64,7 @@ public function rewind(): void
/**
* Return the section's or property's value of the current iteration
*
* @return mixed
* @return TValue
*/
#[\ReturnTypeWillChange]
public function current()
Expand Down Expand Up @@ -115,7 +119,7 @@ public function __isset($key)
*
* @param string $key The name of the property or section
*
* @return mixed|NULL The value or NULL in case $key does not exist
* @return ?TValue The value or NULL in case $key does not exist
*/
public function __get($key)
{
Expand All @@ -126,7 +130,7 @@ public function __get($key)
* Add a new property or section
*
* @param string $key The name of the new property or section
* @param mixed $value The value to set for the new property or section
* @param TValue $value The value to set for the new property or section
*/
public function __set($key, $value)
{
Expand Down Expand Up @@ -164,7 +168,7 @@ public function offsetExists($key): bool
*
* @param string $key The name of the property or section
*
* @return ?mixed The value or NULL in case $key does not exist
* @return ?TValue The value or NULL in case $key does not exist
*/
#[\ReturnTypeWillChange]
public function offsetGet($key)
Expand All @@ -176,7 +180,7 @@ public function offsetGet($key)
* Add a new property or section
*
* @param string $key The name of the new property or section
* @param mixed $value The value to set for the new property or section
* @param TValue $value The value to set for the new property or section
*
* @throws ProgrammingError If the key is null
*/
Expand Down Expand Up @@ -213,9 +217,9 @@ public function isEmpty()
* Return the value for the given property or the config for the given section
*
* @param string $key The name of the property or section
* @param mixed $default The value to return in case the property or section is missing
* @param ?TValue $default The value to return in case the property or section is missing
*
* @return mixed
* @return ?TValue The value or $default in case $key does not exist
*/
public function get($key, $default = null)
{
Expand All @@ -229,7 +233,7 @@ public function get($key, $default = null)
/**
* Return all section and property names
*
* @return array
* @return string[]
*/
public function keys()
{
Expand All @@ -239,7 +243,7 @@ public function keys()
/**
* Return this config's data as associative array
*
* @return array
* @return array<string, TValue>
*/
public function toArray()
{
Expand All @@ -258,7 +262,7 @@ public function toArray()
/**
* Merge the given data with this config
*
* @param array|ConfigObject $data An array or a config
* @param array<string, TValue>|ConfigObject<TValue> $data An array or a config
*
* @return $this
*/
Expand Down

0 comments on commit d6881e0

Please sign in to comment.