Completed
Pull Request — master (#52)
by
unknown
04:44
created

SMDisplayAjaxMap   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 4
c 4
b 0
f 1
lcom 1
cbo 5
dl 0
loc 92
ccs 0
cts 37
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
B getParameterInfo() 0 25 2
B render() 0 32 1
1
<?php
2
3
/**
4
 * Class for the 'display_map_ajax' parser hooks.
5
 *
6
 * @since 0.7
7
 *
8
 * @licence GNU GPL v2+
9
 * @author Jeroen De Dauw < [email protected] >
10
 * @author Peter Grassberger < [email protected] >
11
 */
12
class SMDisplayAjaxMap extends MapsDisplayMap {
13
14
    /**
15
     * Gets the name of the parser hook.
16
     * @see ParserHook::getName
17
     *
18
     * @since 0.7
19
     *
20
     * @return string
21
     */
22
    protected function getName() {
23
        return 'display_ajax_map';
24
    }
25
26
    /**
27
     * Returns an array containing the parameter info.
28
     * @see ParserHook::getParameterInfo
29
     *
30
     * @since 0.7
31
     *
32
     * @return array
33
     */
34
    protected function getParameterInfo( $type ) {
35
        $params = MapsMapper::getCommonParameters();
0 ignored issues
show
Deprecated Code introduced by
The method MapsMapper::getCommonParameters() has been deprecated.

This method has been deprecated.

Loading history...
36
37
        $params['mappingservice']['feature'] = 'display_ajax_map';
38
39
        $params['coordinates'] = array(
40
            //'type' => 'mapslocation',
41
            //'aliases' => array( 'coords', 'location', 'address', 'addresses', 'locations', 'points' ),
42
            'dependencies' => array( 'mappingservice', 'geoservice' ),
43
            'default' => '',
44
            'islist' => true,
45
            'delimiter' => $type === ParserHook::TYPE_FUNCTION ? ';' : "\n",
46
            'message' => 'maps-displaymap-par-coordinates',
47
        );
48
49
        $params['ajax'] = array(
50
            'type' => 'boolean',
51
            'default' => true,
52
            'message' => 'maps-displaymap-par-ajax',
53
        );
54
55
        $params = array_merge( $params, self::getCommonMapParams() );
0 ignored issues
show
Deprecated Code introduced by
The method MapsDisplayMap::getCommonMapParams() has been deprecated.

This method has been deprecated.

Loading history...
56
57
        return $params;
58
    }
59
60
    /**
61
     * Renders and returns the output.
62
     * @see ParserHook::render
63
     *
64
     * @since 0.7
65
     *
66
     * @param array $parameters
67
     *
68
     * @return string
69
     */
70
    public function render( array $parameters ) {
71
        // Get the instance of the service class.
72
        $service = MapsMappingServices::getServiceInstance( $parameters['mappingservice'], $this->getName() );
0 ignored issues
show
Unused Code introduced by
The call to MapsMappingServices::getServiceInstance() has too many arguments starting with $this->getName().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
73
        $mapName = $service->getMapId();
74
75
        $fullParams = $this->validator->getParameters();
0 ignored issues
show
Unused Code introduced by
$fullParams is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Deprecated Code introduced by
The method ParamProcessor\Processor::getParameters() has been deprecated with message: since 1.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
76
77
        $configVars = Skin::makeVariablesScript( $service->getConfigVariables() );
78
        $service->addDependencies( $this->parser );
79
        $this->parser->getOutput()->addHeadItem( $configVars );
80
81
        /*if ( array_key_exists( 'zoom', $fullParams ) && $fullParams['zoom']->wasSetToDefault() && count( $parameters['coordinates'] ) > 1 ) {
82
            $parameters['zoom'] = false;
83
        }
84
85
        $this->parser->addTrackingCategory( 'maps-tracking-category' );*/
86
87
        return Html::rawElement(
88
            'div',
89
            array(
90
                'id' => $mapName,
91
                'style' => "width: {$parameters['width']}; height: {$parameters['height']}; background-color: #cccccc; overflow: hidden;",
92
                'class' => 'maps-map maps-' . $service->getName()
93
            ),
94
            wfMessage( 'maps-loading-map' )->inContentLanguage()->escaped() .
95
            Html::element(
96
                'div',
97
                array( 'style' => 'display:none', 'class' => 'mapdata' ),
98
                FormatJson::encode( $parameters )
99
            )
100
        );
101
    }
102
103
}
104