ArrayChecker::checkFixedArray()   B
last analyzed

Complexity

Conditions 9
Paths 4

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 0
cts 17
cp 0
rs 7.756
c 0
b 0
f 0
cc 9
eloc 11
nc 4
nop 3
crap 90
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