ArrayChecker   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 0
dl 0
loc 32
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B checkFixedArray() 0 19 9
1
<?php
2
namespace Disque\Command\Argument;
3
4
trait ArrayChecker
5
{
6
    /**
7
     * Check that the exact specified $count arguments are defined,
8
     * in a numeric array and that the array is dense, ie. doesn't contain
9
     * any holes in the numeric indexes.
10
     *
11
     * @param mixed $elements Elements (should be an array)
12
     * @param int $count Number of elements expected
13
     * @param bool $atLeast Se to true to check array has at least $count elements
14
     * @return bool Success
15
     */
16
    protected function checkFixedArray($elements, $count, $atLeast = false)
17
    {
18
        if (
19
            empty($elements) ||
20
            !is_array($elements) ||
21
            (!$atLeast && count($elements) !== $count) ||
22
            ($atLeast && count($elements) < $count)
23
        ) {
24
            return false;
25
        }
26
27
        for ($i=0; $i < $count; $i++) {
28
            if (!isset($elements[$i])) {
29
                return false;
30
            }
31
        }
32
33
        return true;
34
    }
35
}
36