ArrayField   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 44.44 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 12
loc 27
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
B validateCastValue() 12 19 5
A type() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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