Completed
Push — master ( a4deca...b10287 )
by Ori
01:31
created

ArrayField::type()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
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