Conditions | 5 |
Paths | 5 |
Total Lines | 19 |
Code Lines | 14 |
Lines | 12 |
Ratio | 63.16 % |
Changes | 0 |
1 | <?php |
||
7 | protected function validateCastValue($val) |
||
8 | { |
||
9 | if (is_array($val)) { |
||
10 | return $val; |
||
11 | View Code Duplication | } elseif (is_string($val)) { |
|
|
|||
12 | try { |
||
13 | $val = json_decode($val); |
||
14 | } catch (\Exception $e) { |
||
15 | throw $this->getValidationException($e->getMessage(), $val); |
||
16 | } |
||
17 | if (!is_array($val)) { |
||
18 | throw $this->getValidationException('json string must decode to array', $val); |
||
19 | } else { |
||
20 | return $val; |
||
21 | } |
||
22 | } else { |
||
23 | throw $this->getValidationException('must be array or string', $val); |
||
24 | } |
||
25 | } |
||
26 | |||
32 |
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.