Completed
Push — version-4 ( a26cca...5903bf )
by
unknown
02:38
created

TypeChecker::isIterable()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 4
nc 2
nop 1
dl 8
loc 8
rs 9.2
c 1
b 0
f 1
1
<?php
2
3
namespace Fenos\Notifynder\Helpers;
4
5
use Traversable;
6
use DateTime;
7
use Carbon\Carbon;
8
use InvalidArgumentException;
9
10
class TypeChecker
11
{
12
    public function isString($value)
13
    {
14
        if (! is_string($value)) {
15
            throw new InvalidArgumentException('The value passed must be a string');
16
        }
17
18
        return true;
19
    }
20
21
    public function isNumeric($value)
22
    {
23
        if (! is_numeric($value)) {
24
            throw new InvalidArgumentException('The value passed must be a number');
25
        }
26
27
        return true;
28
    }
29
30
    public function isDate($value)
31
    {
32
        if ($value instanceof Carbon || $value instanceof DateTime) {
33
            return true;
34
        }
35
36
        throw new InvalidArgumentException('The value passed must be an instance of Carbon\\Carbon or DateTime');
37
    }
38
39 View Code Duplication
    public function isArray($value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41
        if (is_array($value) && count($value) > 0) {
42
            return true;
43
        }
44
45
        throw new InvalidArgumentException('The value passed must be an array');
46
    }
47
48 View Code Duplication
    public function isIterable($value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
    {
50
        if ((is_array($value) || $value instanceof Traversable) && count($value) > 0) {
51
            return true;
52
        }
53
54
        throw new InvalidArgumentException('The value passed must be iterable');
55
    }
56
}
57