contains()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 2
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace BrenoRoosevelt;
5
6
/**
7
 * Checks if ALL elements exists in a collection
8
 * The element index (key) is irrelevant for this operation
9
 * This function uses strict comparison to determine if element exists
10
 *
11
 * @param  iterable $items       The collection
12
 * @param  mixed    ...$elements The searched elements
13
 * @return bool True if ALL elements were found in the collection, false otherwise
14
 */
15
function contains(iterable $items, ...$elements): bool
16
{
17
    foreach ($elements as $element) {
18
        if (index_of($items, $element) === false) {
19
            return false;
20
        }
21
    }
22
23
    return true;
24
}
25