GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

DirtChecker   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 64
Duplicated Lines 18.75 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 0
dl 12
loc 64
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 4
B isDirty() 12 32 7
A turnToNumber() 0 4 1

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 declare (strict_types=1);
2
/**
3
 * @license MIT
4
 * @author Samuel Adeshina <[email protected]>
5
 *
6
 * This file is part of the EmmetBlue project, please read the license document
7
 * available in the root level of the project
8
 */
9
namespace EmmetBlue\Core;
10
11
/**
12
 * Class DirtChecker
13
 *
14
 * @author Samuel Adeshina <[email protected]>
15
 *
16
 * @since v0.0.1 14/12/2016
17
 */
18
class DirtChecker
19
{
20
    public $dirtFilterConditions = [">", "<", "="];
21
22
    public $workingValue;
23
    public $conditionValue;
24
    public $workingConditions = [];
25
26
    public function __construct(string $value, string $conditionValue, array $conditions = [])
27
    {
28
        $this->workingValue = $value;
29
        $this->conditionValue = $conditionValue;
30
31
        if (!empty($conditions)){
32
            foreach ($conditions as $value) {
33
                if (!in_array($value, $this->dirtFilterConditions)){
34
                    throw new \Exception("Invalid Dirt Filter Condition Provided: ".$value);
35
                }
36
            }
37
            $this->workingConditions = $conditions;
38
        }
39
        else {
40
            $this->workingConditions = $this->dirtFilterConditions;
41
        }
42
    }
43
44
    public function isDirty() : bool
45
    {
46
        $explodedString = explode(" ", $this->workingValue);
47
        foreach ($explodedString as $string){
48
            foreach ($this->workingConditions as $condition){
49
                $switchValue = false;
50
                switch ($condition) {
51
                    case '=':
52
                        $switchValue = strpos($string, $this->conditionValue) !== false;
53
                        break;
54 View Code Duplication
                    case '>':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
55
                        $string = self::turnToNumber($string);
56
                        $_condition = self::turnToNumber($this->conditionValue);
57
58
                        $switchValue = $string > $_condition;
59
                        break;
60 View Code Duplication
                    case '<':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
61
                        $string = self::turnToNumber($string);
62
                        $_condition = self::turnToNumber($this->conditionValue);
63
64
                        $switchValue = $string < $_condition;
65
                        break;
66
                }
67
68
                if (!$switchValue) {
69
                    return true;
70
                }
71
            }
72
        }
73
74
        return false;
75
    }
76
77
    private function turnToNumber(string $string) : float 
78
    {
79
        return (float) filter_var($string, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION | FILTER_FLAG_ALLOW_THOUSAND);
80
    }
81
}
82