Issues (20)

src/lang/parts/InsertPart.php (1 issue)

1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the Phootwork package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 *
7
 * @license MIT License
8
 * @copyright Thomas Gossmann
9
 */
10
namespace phootwork\lang\parts;
11
12
trait InsertPart {
13
	abstract public function add(mixed ...$elements);
14
15
	/**
16
	 * Insert one element at the given index
17
	 *
18
	 * @param mixed $element
19
	 * @param int|null|string $index
20
	 *
21
	 * @return $this
22
	 */
23 7
	public function insert(mixed $element, int|string|null $index): self {
24 7
		if (null === $index) {
25 2
			return $this->add($element);
26
		}
27
28 7
		is_int($index) ? array_splice($this->array, $index, 0, [$element])
29 2
			: $this->array[$index] = $element;
0 ignored issues
show
Bug Best Practice introduced by
The property array does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
30
31 7
		return $this;
32
	}
33
}
34