1 | <?php |
||
2 | |||
3 | namespace Siren; |
||
4 | |||
5 | use LogicException; |
||
6 | |||
7 | class Field |
||
8 | { |
||
9 | /** |
||
10 | * @var string |
||
11 | */ |
||
12 | protected $name; |
||
13 | |||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $type; |
||
18 | |||
19 | /** |
||
20 | * @var mixed |
||
21 | */ |
||
22 | protected $value; |
||
23 | |||
24 | /** |
||
25 | * Get name |
||
26 | * |
||
27 | * @return string |
||
28 | */ |
||
29 | public function getName() |
||
30 | { |
||
31 | return $this->name; |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * Set name |
||
36 | * |
||
37 | * @param string $name |
||
38 | * @return $this |
||
39 | * @throws LogicException |
||
40 | */ |
||
41 | View Code Duplication | public function setName($name) |
|
0 ignored issues
–
show
|
|||
42 | { |
||
43 | if (!is_string($name)) { |
||
44 | $exMsg = sprintf('Provided name `%s` is not a string', $name); |
||
45 | throw new LogicException($exMsg); |
||
46 | } |
||
47 | |||
48 | $this->name = $name; |
||
49 | |||
50 | return $this; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Get type |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | public function getType() |
||
59 | { |
||
60 | return $this->type; |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Set type |
||
65 | * |
||
66 | * @param string $type |
||
67 | * @return $this |
||
68 | * @throws LogicException |
||
69 | */ |
||
70 | View Code Duplication | public function setType($type) |
|
0 ignored issues
–
show
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. ![]() |
|||
71 | { |
||
72 | if (!is_string($type)) { |
||
73 | $exMsg = sprintf('Provided type `%s` is not a string', $type); |
||
74 | throw new LogicException($exMsg); |
||
75 | } |
||
76 | |||
77 | $this->type = $type; |
||
78 | |||
79 | return $this; |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Get value |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | public function getValue() |
||
88 | { |
||
89 | return $this->value; |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Set value |
||
94 | * |
||
95 | * @param mixed $value |
||
96 | * @return $this |
||
97 | */ |
||
98 | public function setValue($value) |
||
99 | { |
||
100 | $this->value = $value; |
||
101 | |||
102 | return $this; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * Convert object to array |
||
107 | * |
||
108 | * @return array |
||
109 | */ |
||
110 | public function toArray() |
||
111 | { |
||
112 | $data = array(); |
||
113 | |||
114 | $name = $this->getName(); |
||
115 | if ($name !== null) { |
||
116 | $data['name'] = $name; |
||
117 | } |
||
118 | |||
119 | $type = $this->getType(); |
||
120 | if ($type !== null) { |
||
121 | $data['type'] = $type; |
||
122 | } |
||
123 | |||
124 | $value = $this->getValue(); |
||
125 | if ($value !== null) { |
||
126 | $data['value'] = $value; |
||
127 | } |
||
128 | |||
129 | return $data; |
||
130 | } |
||
131 | } |
||
132 |
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.