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.
|
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.0.4
|
||||||
|
|
||||||
1. PHP Coding Standards Fixer > update configuration
|
1. PHP Coding Standards Fixer > update configuration
|
||||||
|
|||||||
@@ -23,17 +23,16 @@ trait AddTrait
|
|||||||
*
|
*
|
||||||
* @param mixed $element The element to add
|
* @param mixed $element The element to add
|
||||||
* @param mixed $index (optional) Index / key of the element
|
* @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) {
|
if (null === $index || '' === $index) {
|
||||||
$this->elements[] = $element;
|
$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 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
|
* @param bool|false $useIndexes (optional) If is set to true, indexes of given elements will be used in
|
||||||
* this collection. Otherwise - not.
|
* 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)) {
|
if (empty($elements)) {
|
||||||
foreach ($elements as $index => $element) {
|
return;
|
||||||
if ($useIndexes) {
|
|
||||||
$this->add($element, $index);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->add($element);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
* Prepends given element (adds given element at the beginning of collection)
|
||||||
*
|
*
|
||||||
* @param mixed $element The element to prepend
|
* @param mixed $element The element to prepend
|
||||||
* @return $this
|
|
||||||
*/
|
*/
|
||||||
public function prepend($element): self
|
public function prepend($element): void
|
||||||
{
|
{
|
||||||
array_unshift($this->elements, $element);
|
array_unshift($this->elements, $element);
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes given element
|
* Removes given element
|
||||||
*
|
*
|
||||||
* @param mixed $element The element to remove
|
* @param mixed $element The element to remove
|
||||||
* @return $this
|
|
||||||
*/
|
*/
|
||||||
public function remove($element): self
|
public function remove($element): void
|
||||||
{
|
{
|
||||||
if ($this->count() > 0) {
|
if (0 === $this->count()) {
|
||||||
foreach ($this->elements as $index => $existing) {
|
return;
|
||||||
if ($element === $existing) {
|
|
||||||
unset($this->elements[$index]);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
foreach ($this->elements as $index => $existing) {
|
||||||
|
if ($element === $existing) {
|
||||||
|
unset($this->elements[$index]);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user