Validator::isArray()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
namespace TestMonitor\DoneDone;
4
5
use TestMonitor\DoneDone\Exceptions\InvalidDataException;
6
7
class Validator
8
{
9
    /**
10
     * @param mixed $subject
11
     *
12
     * @throws \TestMonitor\DoneDone\Exceptions\InvalidDataException
13
     *
14
     * @return bool
15
     */
16 2
    public static function isInteger($subject)
17
    {
18 2
        if (! is_integer($subject)) {
19 1
            throw new InvalidDataException($subject);
20
        }
21
22 1
        return true;
23
    }
24
25
    /**
26
     * @param mixed $subject
27
     *
28
     * @throws \TestMonitor\DoneDone\Exceptions\InvalidDataException
29
     *
30
     * @return bool
31
     */
32 2
    public static function isString($subject)
33
    {
34 2
        if (! is_string($subject)) {
35 1
            throw new InvalidDataException($subject);
36
        }
37
38 1
        return true;
39
    }
40
41
    /**
42
     * @param mixed $subject
43
     *
44
     * @throws \TestMonitor\DoneDone\Exceptions\InvalidDataException
45
     *
46
     * @return bool
47
     */
48 10
    public static function isArray($subject)
49
    {
50 10
        if (! is_array($subject)) {
51 1
            throw new InvalidDataException($subject);
52
        }
53
54 9
        return true;
55
    }
56
57
    /**
58
     * @param mixed $haystack
59
     * @param mixed $needle
60
     *
61
     * @throws \TestMonitor\DoneDone\Exceptions\InvalidDataException
62
     *
63
     * @return bool
64
     */
65 13
    public static function keyExists($haystack, $needle)
66
    {
67 13
        if (! array_key_exists($needle, $haystack)) {
68 3
            throw new InvalidDataException($haystack);
69
        }
70
71 11
        return true;
72
    }
73
74
    /**
75
     * @param mixed $haystack
76
     * @param array $needles
77
     *
78
     * @throws \TestMonitor\DoneDone\Exceptions\InvalidDataException
79
     *
80
     * @return bool
81
     */
82 11
    public static function keysExists($haystack, array $needles)
83
    {
84 11
        foreach ($needles as $needle) {
85 11
            self::keyExists($haystack, $needle);
86
        }
87
88 9
        return true;
89
    }
90
}
91