Conditions | 3 |
Paths | 3 |
Total Lines | 14 |
Code Lines | 9 |
Lines | 11 |
Ratio | 78.57 % |
Changes | 0 |
1 | <?php |
||
9 | protected function validateCastValue($val) |
||
10 | { |
||
11 | View Code Duplication | if (!is_string($val)) { |
|
|
|||
12 | throw $this->getValidationException('must be string', $val); |
||
13 | } else { |
||
14 | $val = trim($val); |
||
15 | try { |
||
16 | // we create a dateInterval first, because it's more restrictive |
||
17 | return CarbonInterval::instance(new \DateInterval($val)); |
||
18 | } catch (\Exception $e) { |
||
19 | throw $this->getValidationException($e->getMessage(), $val); |
||
20 | } |
||
21 | } |
||
22 | } |
||
23 | |||
47 |
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.