Completed
Push — master ( 5d4822...d1d02b )
by Maik
01:58
created

Arrays::hasElement()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 2
eloc 2
nc 2
nop 2
crap 2
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
     * Create an empty array containing a specific number of elements
22
     *
23
     * @param int $numElements The number of elements in Array
24
     * @return array
25
     */
26 1
    public static function createEmptyArray($numElements):ArrayObject
27
    {
28 1
        return new ArrayObject(array_fill(0, $numElements, null));
29
    }
30
    
31
    /**
32
     * Check whether a key exists in array and corresponding value is not empty
33
     * 
34
     * @param array $array
35
     * @param mixed $element
36
     * @return bool
37
     */
38 20
    public static function hasElement(array $array, $element):bool
39
    {
40 20
    	return isset($array[$element]) && strlen($array[$element]) > 0;
41
    }
42
}
43