RemovePart   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 29
ccs 12
cts 12
cp 1
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A remove() 0 11 3
A reorderList() 0 8 3
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 RemovePart {
13
	/**
14
	 * Removes one or more elements from the array
15
	 *
16
	 * @param mixed ...$elements
17
	 *
18
	 * @return $this
19
	 */
20 7
	public function remove(mixed ...$elements): self {
21
		/** @var mixed $element */
22 7
		foreach ($elements as $element) {
23 7
			$index = array_search($element, $this->array, true);
24 7
			if ($index !== false) {
25 7
				unset($this->array[$index]);
26 7
				$this->reorderList();
27
			}
28
		}
29
30 7
		return $this;
31
	}
32
33 7
	private function reorderList(): void {
34 7
		if (count(array_filter(array_keys($this->array), 'is_string')) > 0) {
35
			//it's an associative array: do nothing
36 1
			return;
37
		}
38
39 6
		if (!array_is_list($this->array)) {
40 5
			$this->array = array_values($this->array);
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...
41
		}
42
	}
43
}
44