Code Duplication    Length = 11-12 lines in 2 locations

src/Fields/ArrayField.php 1 location

@@ 11-22 (lines=12) @@
8
    {
9
        if (is_array($val)) {
10
            return $val;
11
        } 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
    }

src/Fields/DurationField.php 1 location

@@ 11-21 (lines=11) @@
8
{
9
    protected function validateCastValue($val)
10
    {
11
        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
24
    public static function type()