GoogleStreetViewShortCodeHandler::resetCounter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
class GoogleStreetViewShortCodeHandler
4
{
5
    /* Counter used to ensure unique div ids to allow for multiple StreetViews on on page */
6
    private static $gsv_ctr = 1;
7
8 5
    public static function parse_googlestreetview($arguments, $caption = null, $parser = null)
0 ignored issues
show
Unused Code introduced by
The parameter $caption is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $parser is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Method name "GoogleStreetViewShortCodeHandler::parse_googlestreetview" is not in camel caps format
Loading history...
9
    {
10
        // each of latitude, longitude and heading are required at a bare minimum
11 5
        if (!isset($arguments['latitude'])) {
12 1
            return '';
13
        }
14
15 4
        if (!isset($arguments['longitude'])) {
16 1
            return '';
17
        }
18
19 3
        if (!isset($arguments['heading'])) {
20 1
            return '';
21
        }
22
23
        // defaults - these can be overriden by using zoom and pitch in the shortcode
24
        $defaults = array(
25 2
            'Zoom' => 1,
26 2
            'Pitch' => 0,
27 2
        );
28
29
        // ensure JavaScript for the map service is only downloaded once
30 2
        $arguments['DownloadJS'] = !MapUtil::get_map_already_rendered();
31 2
        MapUtil::set_map_already_rendered(true);
32
33
        // convert parameters to CamelCase as per standard template conventions
34 2
        $arguments['Latitude'] = $arguments['latitude'];
35 2
        $arguments['Longitude'] = $arguments['longitude'];
36 2
        $arguments['Heading'] = $arguments['heading'];
37
38
        // optional parameter caption
39 2
        if (isset($arguments['caption'])) {
40 2
            $arguments['Caption'] = $arguments['caption'];
41 2
        }
42
43
        // optional parameter pitch
44 2
        if (isset($arguments['pitch'])) {
45 2
            $arguments['Pitch'] = $arguments['pitch'];
46 2
        }
47
48
        // optional parameter zoom
49 2
        if (isset($arguments['zoom'])) {
50 1
            $arguments['Zoom'] = $arguments['zoom'];
51 1
        }
52
53
        // the id of the dom element to be used to render the street view
54 2
        $arguments['DomID'] = 'google_streetview_'.self::$gsv_ctr;
55
56
        // incrememt the counter to ensure a unique id for each map canvas
57 2
        ++self::$gsv_ctr;
58
59
        // merge defaults and arguments
60 2
        $customised = array_merge($defaults, $arguments);
61
62
        // Include google maps JS at the end of the page
63
        //Requirements::javascriptTemplate("mappable/javascript/google/streetview.google.template.js", $customised);
64
65
        //get streetview template template
66 2
        $template = new SSViewer('GoogleStreetView');
67
68
        //return the template customised with the parmameters
69 2
        return $template->process(new ArrayData($customised));
70
    }
71
72
    /**
73
     * This is only used for testing, otherwise the sequence of tests change the number returned.
74
     */
75 5
    public static function resetCounter()
76
    {
77 5
        self::$gsv_ctr = 1;
78 5
    }
79
}
80