Completed
Push — master ( 10b44f...a11b2a )
by Thijs
17:21 queued 17:19
created

Validator::isInteger()   A

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
     * @return bool
14
     */
15 2
    public static function isInteger($subject)
16
    {
17 2
        if (! is_integer($subject)) {
18 1
            throw new InvalidDataException($subject);
19
        }
20
21 1
        return true;
22
    }
23
24
    /**
25
     * @param mixed $subject
26
     *
27
     * @throws \TestMonitor\DoneDone\Exceptions\InvalidDataException
28
     * @return bool
29
     */
30 2
    public static function isString($subject)
31
    {
32 2
        if (! is_string($subject)) {
33 1
            throw new InvalidDataException($subject);
34
        }
35
36 1
        return true;
37
    }
38
39
    /**
40
     * @param mixed $subject
41
     *
42
     * @throws \TestMonitor\DoneDone\Exceptions\InvalidDataException
43
     * @return bool
44
     */
45 10
    public static function isArray($subject)
46
    {
47 10
        if (! is_array($subject)) {
48 1
            throw new InvalidDataException($subject);
49
        }
50
51 9
        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 13
    public static function keyExists($haystack, $needle)
62
    {
63 13
        if (! array_key_exists($needle, $haystack)) {
64 3
            throw new InvalidDataException($haystack);
65
        }
66
67 11
        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 11
    public static function keysExists($haystack, array $needles)
78
    {
79 11
        foreach ($needles as $needle) {
80 11
            self::keyExists($haystack, $needle);
81
        }
82
83 9
        return true;
84
    }
85
}
86