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) |
|
|
|
|
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) |
|
|
|
|
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
|
|
|
|
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.