From 2091adc8d063efff26c5e55969e36f5ab84371b4 Mon Sep 17 00:00:00 2001 From: Meritoo Date: Sat, 11 May 2019 00:19:38 +0200 Subject: [PATCH] Collection > trait > return "void" where "self" causes type hinting problem and is not required --- CHANGELOG.md | 4 ++++ VERSION | 2 +- src/Traits/Collection/AddTrait.php | 34 +++++++++++++-------------- src/Traits/Collection/ModifyTrait.php | 26 +++++++++----------- 4 files changed, 32 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69edba8..dd96b21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ Common and useful classes, methods, exceptions etc. +# 1.0.5 + +1. Collection > trait > return "void" where "self" causes type hinting problem and is not required + # 1.0.4 1. PHP Coding Standards Fixer > update configuration diff --git a/VERSION b/VERSION index ee90284..90a27f9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.4 +1.0.5 diff --git a/src/Traits/Collection/AddTrait.php b/src/Traits/Collection/AddTrait.php index b51a921..0714ec9 100644 --- a/src/Traits/Collection/AddTrait.php +++ b/src/Traits/Collection/AddTrait.php @@ -23,17 +23,16 @@ trait AddTrait * * @param mixed $element The element to add * @param mixed $index (optional) Index / key of the element - * @return $this */ - public function add($element, $index = null): self + public function add($element, $index = null): void { if (null === $index || '' === $index) { $this->elements[] = $element; - } else { - $this->elements[$index] = $element; + + return; } - return $this; + $this->elements[$index] = $element; } /** @@ -42,22 +41,21 @@ trait AddTrait * @param array|Collection $elements The elements to add * @param bool|false $useIndexes (optional) If is set to true, indexes of given elements will be used in * this collection. Otherwise - not. - * @return $this */ - public function addMultiple($elements, bool $useIndexes = false): self + public function addMultiple($elements, bool $useIndexes = false): void { - if (!empty($elements)) { - foreach ($elements as $index => $element) { - if ($useIndexes) { - $this->add($element, $index); - - continue; - } - - $this->add($element); - } + if (empty($elements)) { + return; } - return $this; + foreach ($elements as $index => $element) { + if ($useIndexes) { + $this->add($element, $index); + + continue; + } + + $this->add($element); + } } } diff --git a/src/Traits/Collection/ModifyTrait.php b/src/Traits/Collection/ModifyTrait.php index 958e4de..c08e677 100644 --- a/src/Traits/Collection/ModifyTrait.php +++ b/src/Traits/Collection/ModifyTrait.php @@ -20,33 +20,29 @@ trait ModifyTrait * Prepends given element (adds given element at the beginning of collection) * * @param mixed $element The element to prepend - * @return $this */ - public function prepend($element): self + public function prepend($element): void { array_unshift($this->elements, $element); - - return $this; } /** * Removes given element * * @param mixed $element The element to remove - * @return $this */ - public function remove($element): self + public function remove($element): void { - if ($this->count() > 0) { - foreach ($this->elements as $index => $existing) { - if ($element === $existing) { - unset($this->elements[$index]); - - break; - } - } + if (0 === $this->count()) { + return; } - return $this; + foreach ($this->elements as $index => $existing) { + if ($element === $existing) { + unset($this->elements[$index]); + + break; + } + } } }