Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/ArrayAccessTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Yiisoft\Arrays;

/**
* ArrayAccessTrait provides the implementation for [[\IteratorAggregate]], [[\ArrayAccess]] and [[\Countable]].
* ArrayAccessTrait provides the implementation for {@see \IteratorAggregate}, {@see \ArrayAccess} and {@see \Countable}.
*
* Note that ArrayAccessTrait requires the class using it contain a property named `data` which should be an array.
* The data will be exposed by ArrayAccessTrait to support accessing the class object like an array.
Expand All @@ -14,7 +14,7 @@ trait ArrayAccessTrait
{
/**
* Returns an iterator for traversing the data.
* This method is required by the SPL interface [[\IteratorAggregate]].
* This method is required by the SPL interface {@see \IteratorAggregate}.
* It will be implicitly called when you use `foreach` to traverse the collection.
* @return \ArrayIterator an iterator for traversing the cookies in the collection.
*/
Expand All @@ -34,7 +34,7 @@ public function count(): int
}

/**
* This method is required by the interface [[\ArrayAccess]].
* This method is required by the interface {@see \ArrayAccess}.
* @param int $offset the offset to check on
* @return bool
*/
Expand All @@ -44,7 +44,7 @@ public function offsetExists(int $offset): bool
}

/**
* This method is required by the interface [[\ArrayAccess]].
* This method is required by the interface {@see \ArrayAccess}.
* @param int $offset the offset to retrieve element.
* @return mixed the element at the offset, null if no element is found at the offset
*/
Expand All @@ -54,7 +54,7 @@ public function offsetGet(int $offset)
}

/**
* This method is required by the interface [[\ArrayAccess]].
* This method is required by the interface {@see \ArrayAccess}.
* @param int $offset the offset to set element
* @param mixed $item the element value
*/
Expand All @@ -64,7 +64,7 @@ public function offsetSet(int $offset, $item): void
}

/**
* This method is required by the interface [[\ArrayAccess]].
* This method is required by the interface {@see \ArrayAccess}.
* @param int $offset the offset to unset element
*/
public function offsetUnset(int $offset): void
Expand Down
4 changes: 3 additions & 1 deletion src/ArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ public static function getValue($array, $key, $default = null)
}

if (!is_array($array) && !is_object($array)) {
throw new \InvalidArgumentException('getValue() can not get value from ' . gettype($array) . '. Only array and object are supported.');
throw new \InvalidArgumentException(
'getValue() can not get value from ' . gettype($array) . '. Only array and object are supported.'
);
}

if (is_array($key)) {
Expand Down
7 changes: 2 additions & 5 deletions src/ArraySorter.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Arrays;

use InvalidArgumentException;
use Yiisoft\Arrays\ArrayHelper;

class ArraySorter
{
Expand Down Expand Up @@ -60,7 +57,7 @@ public static function multisort(array &$array, $key, $direction = SORT_ASC, $so
* purpose. The anonymous function signature should be: `function($item)`.
* To sort by multiple keys, provide an array of keys here.
*
* @return Array return the keys
* @return array return the keys
*/
private static function getKeys(array &$array, $key): array
{
Expand Down Expand Up @@ -96,7 +93,7 @@ private static function getKeys(array &$array, $key): array
* Please refer to [PHP manual](http://php.net/manual/en/function.sort.php)
* for more details. When sorting by multiple keys with different sort flags, use an array of sort flags.
*
* @return Array return the arguments
* @return array return the arguments
*/
private static function getArguments(array &$array, &$keys, $direction, $sortFlag): array
{
Expand Down
24 changes: 12 additions & 12 deletions src/ArrayableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
/**
* ArrayableInterface should be implemented by classes who want to support customizable representation of their instances.
*
* For example, if a class implements ArrayableInterface, by calling [[toArray()]], an instance of this class
* For example, if a class implements ArrayableInterface, by calling {@see ArrayableInterface::toArray()}, an instance of this class
* can be turned into an array (including all its embedded objects) which can then be further transformed easily
* into other formats, such as JSON, XML.
*
* The methods [[fields()]] and [[extraFields()]] allow the implementing classes to customize how and which of their data
* should be formatted and put into the result of [[toArray()]].
* The methods {@see ArrayableInterface::fields()} and {@see ArrayableInterface::extraFields()} allow the implementing classes to customize how and which of their data
* should be formatted and put into the result of {@see ArrayableInterface::toArray()}.
*/
interface ArrayableInterface
{
/**
* Returns the list of fields that should be returned by default by [[toArray()]] when no specific fields are specified.
* Returns the list of fields that should be returned by default by {@see toArray()} when no specific fields are specified.
*
* A field is a named element in the returned array by [[toArray()]].
* A field is a named element in the returned array by {@see toArray()}.
*
* This method should return an array of field names or field definitions.
* If the former, the field name will be treated as an object property name whose value will be used
Expand Down Expand Up @@ -56,14 +56,14 @@ interface ArrayableInterface
public function fields(): array;

/**
* Returns the list of additional fields that can be returned by [[toArray()]] in addition to those listed in [[fields()]].
* Returns the list of additional fields that can be returned by {@see toArray()} in addition to those listed in {@see fields()}.
*
* This method is similar to [[fields()]] except that the list of fields declared
* by this method are not returned by default by [[toArray()]]. Only when a field in the list
* is explicitly requested, will it be included in the result of [[toArray()]].
* This method is similar to {@see fields()} except that the list of fields declared
* by this method are not returned by default by {@see toArray()}. Only when a field in the list
* is explicitly requested, will it be included in the result of {@see toArray()}.
*
* @return array the list of expandable field names or field definitions. Please refer
* to [[fields()]] on the format of the return value.
* to {@see fields()} on the format of the return value.
* @see toArray()
* @see fields()
*/
Expand All @@ -73,9 +73,9 @@ public function extraFields(): array;
* Converts the object into an array.
*
* @param array $fields the fields that the output array should contain. Fields not specified
* in [[fields()]] will be ignored. If this parameter is empty, all fields as specified in [[fields()]] will be returned.
* in {@see fields()} will be ignored. If this parameter is empty, all fields as specified in {@see fields()} will be returned.
* @param array $expand the additional fields that the output array should contain.
* Fields not specified in [[extraFields()]] will be ignored. If this parameter is empty, no extra fields
* Fields not specified in {@see extraFields()} will be ignored. If this parameter is empty, no extra fields
* will be returned.
* @param bool $recursive whether to recursively return array representation of embedded objects.
* @return array the array representation of the object
Expand Down
32 changes: 16 additions & 16 deletions src/ArrayableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
namespace Yiisoft\Arrays;

/**
* ArrayableTrait provides a common implementation of the [[Arrayable]] interface.
* ArrayableTrait provides a common implementation of the {@see ArrayableInterface} interface.
*
* ArrayableTrait implements [[toArray()]] by respecting the field definitions as declared
* in [[fields()]] and [[extraFields()]].
* ArrayableTrait implements {@see ArrayableInterface::toArray()} by respecting the field definitions as declared
* in {@see ArrayableInterface::fields()} and {@see ArrayableInterface::extraFields()}.
*/
trait ArrayableTrait
{
/**
* Returns the list of fields that should be returned by default by [[toArray()]] when no specific fields are specified.
* Returns the list of fields that should be returned by default by {@see ArrayableInterface::toArray()} when no specific fields are specified.
*
* A field is a named element in the returned array by [[toArray()]].
* A field is a named element in the returned array by {@see ArrayableInterface::toArray()}.
*
* This method should return an array of field names or field definitions.
* If the former, the field name will be treated as an object property name whose value will be used
Expand Down Expand Up @@ -62,11 +62,11 @@ public function fields(): array
}

/**
* Returns the list of fields that can be expanded further and returned by [[toArray()]].
* Returns the list of fields that can be expanded further and returned by {@see ArrayableInterface::toArray()}.
*
* This method is similar to [[fields()]] except that the list of fields returned
* by this method are not returned by default by [[toArray()]]. Only when field names
* to be expanded are explicitly specified when calling [[toArray()]], will their values
* This method is similar to {@see ArrayableInterface::fields()} except that the list of fields returned
* by this method are not returned by default by {@see ArrayableInterface::toArray()}]. Only when field names
* to be expanded are explicitly specified when calling {@see ArrayableInterface::toArray()}, will their values
* be exported.
*
* The default implementation returns an empty array.
Expand All @@ -75,7 +75,7 @@ public function fields(): array
* (e.g. the current application user).
*
* @return array the list of expandable field names or field definitions. Please refer
* to [[fields()]] on the format of the return value.
* to {@see ArrayableInterface::fields()} on the format of the return value.
* @see toArray()
* @see fields()
*/
Expand All @@ -87,16 +87,16 @@ public function extraFields(): array
/**
* Converts the model into an array.
*
* This method will first identify which fields to be included in the resulting array by calling [[resolveFields()]].
* This method will first identify which fields to be included in the resulting array by calling {@see resolveFields()}.
* It will then turn the model into an array with these fields. If `$recursive` is true,
* any embedded objects will also be converted into arrays.
* When embeded objects are [[Arrayable]], their respective nested fields will be extracted and passed to [[toArray()]].
* When embedded objects are {@see ArrayableInterface}, their respective nested fields will be extracted and passed to {@see ArrayableInterface::toArray()}.
*
* @param array $fields the fields being requested.
* If empty or if it contains '*', all fields as specified by [[fields()]] will be returned.
* If empty or if it contains '*', all fields as specified by {@see ArrayableInterface::fields()} will be returned.
* Fields can be nested, separated with dots (.). e.g.: item.field.sub-field
* `$recursive` must be true for nested fields to be extracted. If `$recursive` is false, only the root fields will be extracted.
* @param array $expand the additional fields being requested for exporting. Only fields declared in [[extraFields()]]
* @param array $expand the additional fields being requested for exporting. Only fields declared in {@see ArrayableInterface::extraFields()}
* will be considered.
* Expand can also be nested, separated with dots (.). e.g.: item.expand1.expand2
* `$recursive` must be true for nested expands to be extracted. If `$recursive` is false, only the root expands will be extracted.
Expand Down Expand Up @@ -178,9 +178,9 @@ protected function extractFieldsFor(array $fields, string $rootField): array
}

/**
* Determines which fields can be returned by [[toArray()]].
* Determines which fields can be returned by {@see ArrayableInterface::toArray()}.
* This method will first extract the root fields from the given fields.
* Then it will check the requested root fields against those declared in [[fields()]] and [[extraFields()]]
* Then it will check the requested root fields against those declared in {@see ArrayableInterface::fields()} and {@see ArrayableInterface::extraFields()}
* to determine which fields can be returned.
* @param array $fields the fields being requested for exporting
* @param array $expand the additional fields being requested for exporting
Expand Down
2 changes: 1 addition & 1 deletion src/Modifier/ReplaceValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Yiisoft\Arrays\Modifier;

/**
* Object that represents the replacement of array value while performing [[ArrayHelper::merge()]].
* Object that represents the replacement of array value while performing {@see ArrayHelper::merge()}.
*
* Usage example:
*
Expand Down
2 changes: 1 addition & 1 deletion src/Modifier/UnsetValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Yiisoft\Arrays\Modifier;

/**
* Object that represents the removal of array value while performing [[ArrayHelper::merge()]].
* Object that represents the removal of array value while performing {@see ArrayHelper::merge()}.
*
* Usage example:
*
Expand Down