mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +01:00
Collection > trait > return "void" where "self" causes type hinting problem and is not required
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user