GeojsonField   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 35
Duplicated Lines 28.57 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 10
loc 35
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
C validateCastValue() 10 27 7
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 GeojsonField extends BaseField
6
{
7
    protected function validateCastValue($val)
8
    {
9 View Code Duplication
        if (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...
10
            try {
11
                $val = json_decode($val);
12
            } catch (\Exception $e) {
13
                throw $this->getValidationException($e->getMessage(), $val);
14
            }
15
            if (!$val) {
16
                throw $this->getValidationException('failed to decode json', $val);
17
            }
18
        }
19
        $val = json_decode(json_encode($val));
20
        if (!is_object($val)) {
21
            throw $this->getValidationException('must be an object', $val);
22
        }
23
        if ($this->format() == 'default') {
24
            try {
25
                // this validates the geojson
26
                \GeoJson\GeoJson::jsonUnserialize($val);
27
            } catch (\Exception $e) {
28
                throw $this->getValidationException($e->getMessage(), $val);
29
            }
30
        }
31
32
        return $val;
33
    }
34
35
    public static function type()
36
    {
37
        return 'geojson';
38
    }
39
}
40