Completed
Push — master ( e3e5bf...e9f06b )
by Maik
02:00
created

Arrays::hasElement()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.1406

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 3
nop 2
crap 3.1406
1
<?php
2
3
/**
4
 * This file is part of the PHP Generics package.
5
 *
6
 * @package Generics
7
 */
8
namespace Generics\Util;
9
10
use ArrayObject;
11
12
/**
13
 * This class provides some array utility functions
14
 *
15
 * @author Maik Greubel <[email protected]>
16
 *        
17
 */
18
class Arrays
19
{
20
21
    /**
22
     * Create an empty array containing a specific number of elements
23
     *
24
     * @param int $numElements
25
     *            The number of elements in Array
26
     * @return array
27
     */
28 1
    public static function createEmptyArray($numElements): ArrayObject
29
    {
30 1
        return new ArrayObject(array_fill(0, $numElements, null));
31
    }
32
33
    /**
34
     * Check whether a key exists in array and corresponding value is not empty
35
     *
36
     * @param array $array
37
     * @param mixed $element
38
     * @return bool
39
     */
40 20
    public static function hasElement($array, $element): bool
41
    {
42 20
        if (! is_array($array))
43
            return false;
44
        
45 20
        return isset($array[$element]) && strlen($array[$element]) > 0;
46
    }
47
}
48