* @copyright Meritoo */ trait AddTrait { /** * Adds given element (at the end of collection) * * @param mixed $element The element to add * @param mixed $index (optional) Index / key of the element */ public function add($element, $index = null): void { if (!$this->isValidType($element)) { return; } if (null === $index) { $this->elements[] = $element; return; } $this->elements[$index] = $element; } /** * Adds given elements (at the end of collection) * * @param array|BaseCollection $elements The elements to add * @param bool $useIndexes (optional) If is set to true, indexes of given elements will be used in * this collection. Otherwise - not. */ public function addMultiple($elements, bool $useIndexes = false): void { if (empty($elements)) { return; } foreach ($elements as $index => $element) { if ($useIndexes) { $this->add($element, $index); continue; } $this->add($element); } } }