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

TypeChecker   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 47
Duplicated Lines 34.04 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 16
loc 47
rs 10
wmc 14
lcom 0
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A isString() 0 8 2
A isNumeric() 0 8 2
A isDate() 0 8 3
A isArray() 8 8 3
A isIterable() 8 8 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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