Completed
Push — master ( 5a1a70...5d1f10 )
by Thijs
16s queued 13s
created

Validator::isArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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