ArrayField::validateCastValue()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 19
Code Lines 14

Duplication

Lines 12
Ratio 63.16 %

Importance

Changes 0
Metric Value
cc 5
eloc 14
nc 5
nop 1
dl 12
loc 19
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace frictionlessdata\tableschema\Fields;
4
5
class ArrayField extends BaseField
6
{
7
    protected function validateCastValue($val)
8
    {
9
        if (is_array($val)) {
10
            return $val;
11 View Code Duplication
        } elseif (is_string($val)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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.

Loading history...
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
27
    public static function type()
28
    {
29
        return 'array';
30
    }
31
}
32