Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use self return type #45

Merged
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
8 changes: 4 additions & 4 deletions src/Chain.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ public function __construct(array $array = [])
/**
* @param array $array
*
* @return Chain
* @return self
*/
public static function create(array $array = []): Chain
public static function create(array $array = []): self
{
return new static($array);
}
Expand All @@ -115,9 +115,9 @@ public static function create(array $array = []): Chain
* @param array $options If the option `regexp` is `true` the string is split by using `preg_split()`, otherwise
* `explode()` is used.
*
* @return Chain
* @return self
*/
public static function createFromString(string $delimiter, string $string, array $options = []): Chain
public static function createFromString(string $delimiter, string $string, array $options = []): self
{
$options = array_merge(['regexp' => false], $options);
$chain = new static();
Expand Down
6 changes: 2 additions & 4 deletions src/Link/ChangeKeyCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Cocur\Chain\Link;

use Cocur\Chain\Chain;

/**
* Class ChangeKeyCase.
*
Expand All @@ -18,9 +16,9 @@ trait ChangeKeyCase
*
* @param int $case Either `CASE_UPPER` or `CASE_LOWER` (default).
*
* @return Chain
* @return self
*/
public function changeKeyCase(int $case = CASE_LOWER): Chain
public function changeKeyCase(int $case = CASE_LOWER): self
{
$this->array = array_change_key_case($this->array, $case);

Expand Down
4 changes: 2 additions & 2 deletions src/Link/Combine.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ trait Combine
* will be converted to string.
* @param Chain|array $values Array or instance of `Cocur\Chain\Chain` of values to be used.
*
* @return Chain
* @return self
*/
public function combine($keys, $values): Chain
public function combine($keys, $values): self
{
$this->array = array_combine(
$keys instanceof Chain ? $keys->array : $keys,
Expand Down
4 changes: 2 additions & 2 deletions src/Link/Diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ trait Diff
*
* @param Chain|array $array2 An array or instance of `Cocur\Chain\Chain` to compare against.
*
* @return Chain
* @return self
*/
public function diff($array2): Chain
public function diff($array2): self
{
$this->array = array_diff(
$this->array,
Expand Down
6 changes: 2 additions & 4 deletions src/Link/Fill.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Cocur\Chain\Link;

use Cocur\Chain\Chain;

/**
* Fill.
*
Expand All @@ -23,9 +21,9 @@ trait Fill
* @param int $num Number of elements to insert. Must be greater than or equal to zero.
* @param mixed $value Value to use for filling.
*
* @return Chain
* @return self
*/
public static function fill(int $startIndex, int $num, $value = null): Chain
public static function fill(int $startIndex, int $num, $value = null): self
{
return new self(array_fill($startIndex, $num, $value));
}
Expand Down
6 changes: 2 additions & 4 deletions src/Link/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Cocur\Chain\Link;

use Cocur\Chain\Chain;

/**
* Filter.
*
Expand All @@ -20,9 +18,9 @@ trait Filter
*
* @param callable $callback The callback function to use.
*
* @return Chain
* @return self
*/
public function filter(callable $callback): Chain
public function filter(callable $callback): self
{
$this->array = array_filter($this->array, $callback, ARRAY_FILTER_USE_BOTH);

Expand Down
2 changes: 0 additions & 2 deletions src/Link/Find.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Cocur\Chain\Link;

use Cocur\Chain\Chain;

/**
* Find
*
Expand Down
6 changes: 2 additions & 4 deletions src/Link/FlatMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Cocur\Chain\Link;

use Cocur\Chain\Chain;

/**
* FlatMap.
*
Expand All @@ -14,9 +12,9 @@ trait FlatMap
/**
* @param callable $callback
*
* @return Chain
* @return self
*/
public function flatMap(callable $callback): Chain
public function flatMap(callable $callback): self
{
$flattened = [];
foreach ($this->array as $index => $element) {
Expand Down
6 changes: 2 additions & 4 deletions src/Link/Flip.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Cocur\Chain\Link;

use Cocur\Chain\Chain;

/**
* Flip.
*
Expand All @@ -13,9 +11,9 @@
trait Flip
{
/**
* @return Chain
* @return self
*/
public function flip(): Chain
public function flip(): self
{
$this->array = array_flip($this->array);

Expand Down
4 changes: 2 additions & 2 deletions src/Link/Intersect.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ trait Intersect
/**
* @param Chain|array $array2
*
* @return Chain
* @return self
*/
public function intersect($array2): Chain
public function intersect($array2): self
{
$this->array = array_intersect($this->array, $array2 instanceof Chain ? $array2->array : $array2);

Expand Down
4 changes: 2 additions & 2 deletions src/Link/IntersectAssoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ trait IntersectAssoc
/**
* @param Chain|array $array
*
* @return Chain
* @return self
*/
public function intersectAssoc($array): Chain
public function intersectAssoc($array): self
{
$this->array = array_intersect_assoc($this->array, $array instanceof Chain ? $array->array : $array);

Expand Down
4 changes: 2 additions & 2 deletions src/Link/IntersectKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ trait IntersectKey
/**
* @param Chain|array $array
*
* @return Chain
* @return self
*/
public function intersectKey($array): Chain
public function intersectKey($array): self
{
$this->array = array_intersect_key($this->array, $array instanceof Chain ? $array->array : $array);

Expand Down
6 changes: 2 additions & 4 deletions src/Link/Keys.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Cocur\Chain\Link;

use Cocur\Chain\Chain;

/**
* Keys.
*
Expand All @@ -13,9 +11,9 @@
trait Keys
{
/**
* @return Chain
* @return self
*/
public function keys(): Chain
public function keys(): self
{
$this->array = array_keys($this->array);

Expand Down
6 changes: 2 additions & 4 deletions src/Link/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Cocur\Chain\Link;

use Cocur\Chain\Chain;

/**
* Map.
*
Expand All @@ -15,9 +13,9 @@ trait Map
/**
* @param callable $callback
*
* @return Chain
* @return self
*/
public function map(callable $callback): Chain
public function map(callable $callback): self
{
foreach ($this->array as $index => $element) {
$this->array[$index] = $callback($element, $index);
Expand Down
4 changes: 2 additions & 2 deletions src/Link/Merge.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ trait Merge
* @param Chain|array $array Array to merge with
* @param array $options Options, including `recursive` to merge arrays recursive.
*
* @return Chain
* @return self
*/
public function merge($array, array $options = []): Chain
public function merge($array, array $options = []): self
{
$options = array_merge(['recursive' => false], $options);

Expand Down
6 changes: 2 additions & 4 deletions src/Link/Pad.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Cocur\Chain\Link;

use Cocur\Chain\Chain;

/**
* Pad.
*
Expand All @@ -16,9 +14,9 @@ trait Pad
* @param int $size
* @param mixed $value
*
* @return Chain
* @return self
*/
public function pad(int $size, $value): Chain
public function pad(int $size, $value): self
{
$this->array = array_pad($this->array, $size, $value);

Expand Down
6 changes: 2 additions & 4 deletions src/Link/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Cocur\Chain\Link;

use Cocur\Chain\Chain;

/**
* Push.
*
Expand All @@ -15,9 +13,9 @@ trait Push
/**
* @param mixed $element
*
* @return Chain
* @return self
*/
public function push($element): Chain
public function push($element): self
{
array_push($this->array, $element);

Expand Down
4 changes: 2 additions & 2 deletions src/Link/Replace.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ trait Replace
/**
* @param Chain|array $array
*
* @return Chain
* @return self
*/
public function replace($array): Chain
public function replace($array): self
{
$this->array = array_replace($this->array, $array instanceof Chain ? $chain->array : $array);

Expand Down
6 changes: 2 additions & 4 deletions src/Link/Reverse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Cocur\Chain\Link;

use Cocur\Chain\Chain;

/**
* Reverse.
*
Expand All @@ -15,9 +13,9 @@ trait Reverse
/**
* @param bool $preserveKeys
*
* @return Chain
* @return self
*/
public function reverse(bool $preserveKeys = false): Chain
public function reverse(bool $preserveKeys = false): self
{
$this->array = array_reverse($this->array, $preserveKeys);

Expand Down
6 changes: 2 additions & 4 deletions src/Link/Shuffle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Cocur\Chain\Link;

use Cocur\Chain\Chain;

/**
* Shuffle.
*
Expand All @@ -13,9 +11,9 @@
trait Shuffle
{
/**
* @return Chain
* @return self
*/
public function shuffle(): Chain
public function shuffle(): self
{
shuffle($this->array);

Expand Down
6 changes: 2 additions & 4 deletions src/Link/Slice.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Cocur\Chain\Link;

use Cocur\Chain\Chain;

/**
* Slice.
*
Expand All @@ -17,9 +15,9 @@ trait Slice
* @param int|null $length
* @param bool $preserveKeys
*
* @return Chain
* @return self
*/
public function slice(int $offset, ?int $length = null, bool $preserveKeys = false): Chain
public function slice(int $offset, ?int $length = null, bool $preserveKeys = false): self
{
$this->array = array_slice($this->array, $offset, $length, $preserveKeys);

Expand Down
6 changes: 2 additions & 4 deletions src/Link/Sort.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Cocur\Chain\Link;

use Cocur\Chain\Chain;

/**
* Class Sort.
*
Expand All @@ -18,9 +16,9 @@ trait Sort
* @param int|callable $sortBy
* @param array $options
*
* @return Chain
* @return self
*/
public function sort($sortBy = SORT_REGULAR, array $options = []): Chain
public function sort($sortBy = SORT_REGULAR, array $options = []): self
{
if (!$sortBy) {
$sortBy = SORT_REGULAR;
Expand Down
Loading