GoogleMapBasic   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 7
dl 0
loc 62
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B updateCMSFields() 0 25 4
B canHaveMap() 0 18 9
1
<?php
2
3
/**
4
 *@author nicolaas[at] sunnysideup.co.nz
5
 *
6
 *
7
 **/
8
9
10
class GoogleMapBasic extends SiteTreeExtension
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
11
{
12
    private static $db = array(
0 ignored issues
show
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
13
        'ShowMap' => 'Boolean',
14
        'StaticMap' => 'Boolean',
15
        'Address' => 'Text',
16
        'Lat' => 'Decimal(12,9)',
17
        'Lng' => 'Decimal(12,9)',
18
        'ZoomLevel' => 'Int',
19
        'InfoWindowContent' => 'HTMLText'
20
    );
21
22
23
    private static $include_in_classes = array();
0 ignored issues
show
Unused Code introduced by
The property $include_in_classes is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
24
25
    private static $exclude_from_classes = array();
0 ignored issues
show
Unused Code introduced by
The property $exclude_from_classes is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
26
27
    public function updateCMSFields(FieldList $fields)
28
    {
29
        if ($this->canHaveMap()) {
30
            $reloadMessage = " ";
31
            if (!$this->owner->ShowMap) {
0 ignored issues
show
Bug introduced by
The property ShowMap does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
32
                $reloadMessage = " (save (and publish) to see additional options)";
33
            }
34
            $fields->addFieldToTab("Root.Map", new CheckboxField("ShowMap", "Show map $reloadMessage"));
35
            if ($this->owner->ShowMap) {
36
                $fields->addFieldsToTab(
37
                    "Root.Map",
38
                    [
39
                        CheckboxField::create("StaticMap", "Show map as picture only"),
40
                        TextField::create("Address"),
41
                        NumericField::create("ZoomLevel", "Zoom (1 = world, 20 = too close)"),
42
                        NumericField::create("Lat", "Latitude")
43
                            ->setRightTitle('Optional, use in conjunction with Longitude if address is not accurate enough.'),
44
                        NumericField::create("Lng", "Longitude")
45
                            ->setRightTitle('Optional, use in conjunction with Latitude if address is not accurate enough.'),
46
                        HtmlEditorField::create("InfoWindowContent", "Info Window Content")->setRows(5)
47
                    ]
48
                );
49
            }
50
        }
51
    }
52
53
    protected function canHaveMap()
54
    {
55
        $include = Config::inst()->get("GoogleMapBasic", "include_in_classes");
56
        $exclude = Config::inst()->get("GoogleMapBasic", "exclude_from_classes");
57
        if (!is_array($exclude) || !is_array($include)) {
58
            user_error("include or exclude classes is NOT an array", E_USER_NOTICE);
59
            return true;
60
        }
61
        if (!count($include) && !count($exclude)) {
62
            return true;
63
        }
64
        if (count($include) && in_array($this->owner->ClassName, $include)) {
0 ignored issues
show
Bug introduced by
The property ClassName does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
65
            return true;
66
        }
67
        if (count($exclude) && !in_array($this->owner->ClassName, $exclude)) {
68
            return true;
69
        }
70
    }
71
}
72