MapLayerExtension   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 26.32 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 15
loc 57
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A updateCMSFields() 15 18 1
A updateHasGeo() 0 6 2
A updateBasicMap() 0 9 2

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
class MapLayerExtension extends DataExtension
4
{
5
    public static $many_many = array(
6
            'MapLayers' => 'MapLayer',
7
    );
8
9
    public static $belongs_many_many_extraFields = array(
10
        'MapLayers' => array(
11
            'SortOrder' => 'Int',
12
        ),
13
    );
14
15 1 View Code Duplication
    public function updateCMSFields(FieldList $fields)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
16
    {
17 1
        $gridConfig2 = GridFieldConfig_RelationEditor::create();
18 1
        $gridConfig2->getComponentByType(
19 1
            'GridFieldAddExistingAutocompleter'
20 1
        )->
21 1
            setSearchFields(
22 1
                array('Title')
23 1
        );
24 1
        $gridConfig2->getComponentByType('GridFieldPaginator')->setItemsPerPage(100);
25 1
        $gridField2 = new GridField(
26
            'Map Layers',
27 1
            'Map Layers:',
28 1
            $this->owner->MapLayers(),
29 1
            $gridConfig2
30
        );
31
        $fields->addFieldToTab('Root.MapLayers', $gridField2);
32
    }
33
34
    /**
35 10
     * Only set has geo to true if layers exist
36
     * @param  boolean &$hasGeo will be set to true if any layers
37 10
     */
38 1
    public function updateHasGeo(&$hasGeo)
39 1
    {
40 10
        if ($this->owner->MapLayers()->count() > 0) {
41
            $hasGeo = true;
42
        }
43
    }
44
45
    /**
46
     * Add layers if the exist to a map from the MapExtension
47 2
     * @param  MapAPI &$map      object representing the map
48
     * @param  boolean &$autozoom true to auto zoom, false not to
49
     */
50 2
    public function updateBasicMap(&$map, &$autozoom)
51 1
    {
52
        // add any KML map layers
53 1
        foreach ($this->owner->MapLayers() as $layer) {
54 2
            $map->addKML($layer->KmlFile()->getAbsoluteURL());
55 2
            // we have a layer, so turn on autozoom
56
            $autozoom = true;
57 1
        }
58
    }
59
}
60