Parameters   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 75
Duplicated Lines 42.67 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 15
lcom 0
cbo 0
dl 32
loc 75
ccs 41
cts 41
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A pullCountry() 16 16 4
A pullCase() 0 11 3
A pullType() 16 16 4
A getCountry() 0 4 1
A getCase() 0 4 1
A getType() 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
2
3
namespace Tylercd100\Validator\State;
4
5
class Parameters
6
{
7
    protected $country = null;
8
    protected $case = null;
9
    protected $type = null;
10
11 30
    public function __construct($params)
12
    {
13 30
        $params = array_map('strtolower', $params);
14 30
        $this->country = $this->pullCountry($params);
15 30
        $this->case = $this->pullCase($params);
16 30
        $this->type = $this->pullType($params);
17 30
    }
18
19 30 View Code Duplication
    protected function pullCountry($params)
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...
20
    {
21 30
        $z = null;
22
        $x = [
23 30
            "usa" => ["us", "usa"],
24 30
            "canada" => ["ca", "canada"],
25 30
        ];
26
27 30
        foreach ($x as $key => $possibilities) {
28 30
            foreach ($possibilities as $value) {
29 30
                $z = in_array($value, $params) ? $key : $z; 
30 30
            }
31 30
        }
32
33 30
        return $z;
34
    }
35
36 30
    protected function pullCase($params)
37
    {
38 30
        $z = null;
39 30
        $x = ["upper", "lower", "title"];
40
41 30
        foreach ($x as $value) {
42 30
            $z = in_array($value, $params) ? $value : $z;
43 30
        }
44
45 30
        return $z;
46
    }
47
48 30 View Code Duplication
    protected function pullType($params)
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 30
        $z = null;
51
        $x = [
52 30
            "abbr" => ["abbr", "abbrev", "abbreviation"],
53 30
            "full" => ["full", "long", "whole"],
54 30
        ];
55
56 30
        foreach ($x as $key => $possibilities) {
57 30
            foreach ($possibilities as $value) {
58 30
                $z = in_array($value, $params) ? $key : $z;
59 30
            }
60 30
        }
61
62 30
        return $z;
63
    }
64
65 24
    public function getCountry()
66
    {
67 24
        return $this->country;
68
    }
69
70 24
    public function getCase()
71
    {
72 24
        return $this->case;
73
    }
74
75 24
    public function getType()
76
    {
77 24
        return $this->type;
78
    }
79
}
80