Completed
Push — master ( 1f3396...4932db )
by Cristiano
02:20
created

RemovePart::removeAll()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
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
11
namespace phootwork\lang\parts;
12
13
trait RemovePart {
14
	/**
15
	 * Removes an element from the array
16
	 *
17
	 * @param mixed $element
18
	 * @return $this
19
	 */
20 5
	public function remove($element): self {
21 5
		$index = array_search($element, $this->array, true);
22 5
		if ($index !== false) {
23 5
			unset($this->array[$index]);
24
		}
25
26 5
		return $this;
27
	}
28
29
	/**
30
	 * Removes all elements from the array
31
	 *
32
	 * @param array|\Iterator $array
33
	 * @return $this
34
	 */
35 4
	public function removeAll($array): self {
36 4
		foreach ($array as $element) {
37 4
			$this->remove($element);
38
		}
39
40 4
		return $this;
41
	}
42
}
43