Complex classes like MapsDisplayMapRenderer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use MapsDisplayMapRenderer, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 13 | class MapsDisplayMapRenderer { | 
            ||
| 14 | |||
| 15 | /**  | 
            ||
| 16 | * @since 2.0  | 
            ||
| 17 | *  | 
            ||
| 18 | * @var iMappingService  | 
            ||
| 19 | */  | 
            ||
| 20 | protected $service;  | 
            ||
| 21 | |||
| 22 | /**  | 
            ||
| 23 | * Constructor.  | 
            ||
| 24 | *  | 
            ||
| 25 | * @param iMappingService $service  | 
            ||
| 26 | */  | 
            ||
| 27 | 	public function __construct( iMappingService $service ) { | 
            ||
| 30 | |||
| 31 | /**  | 
            ||
| 32 | * Returns the HTML to display the map.  | 
            ||
| 33 | *  | 
            ||
| 34 | * @since 2.0  | 
            ||
| 35 | *  | 
            ||
| 36 | * @param array $params  | 
            ||
| 37 | * @param Parser $parser  | 
            ||
| 38 | * @param string $mapName  | 
            ||
| 39 | *  | 
            ||
| 40 | * @return string  | 
            ||
| 41 | */  | 
            ||
| 42 | 	protected function getMapHTML( array $params, Parser $parser, $mapName ) { | 
            ||
| 43 | return Html::rawElement(  | 
            ||
| 44 | 'div',  | 
            ||
| 45 | [  | 
            ||
| 46 | 'id' => $mapName,  | 
            ||
| 47 | 				'style' => "width: {$params['width']}; height: {$params['height']}; background-color: #cccccc; overflow: hidden;", | 
            ||
| 48 | 'class' => 'maps-map maps-' . $this->service->getName()  | 
            ||
| 49 | ],  | 
            ||
| 50 | wfMessage( 'maps-loading-map' )->inContentLanguage()->escaped() .  | 
            ||
| 51 | Html::element(  | 
            ||
| 52 | 'div',  | 
            ||
| 53 | [ 'style' => 'display:none', 'class' => 'mapdata' ],  | 
            ||
| 54 | FormatJson::encode( $this->getJSONObject( $params, $parser ) )  | 
            ||
| 55 | )  | 
            ||
| 56 | );  | 
            ||
| 57 | }  | 
            ||
| 58 | |||
| 59 | /**  | 
            ||
| 60 | * Returns a PHP object to encode to JSON with the map data.  | 
            ||
| 61 | *  | 
            ||
| 62 | * @since 2.0  | 
            ||
| 63 | *  | 
            ||
| 64 | * @param array $params  | 
            ||
| 65 | * @param Parser $parser  | 
            ||
| 66 | *  | 
            ||
| 67 | * @return mixed  | 
            ||
| 68 | */  | 
            ||
| 69 | 	protected function getJSONObject( array $params, Parser $parser ) { | 
            ||
| 72 | |||
| 73 | /**  | 
            ||
| 74 | * Handles the request from the parser hook by doing the work that's common for all  | 
            ||
| 75 | * mapping services, calling the specific methods and finally returning the resulting output.  | 
            ||
| 76 | *  | 
            ||
| 77 | * @param array $params  | 
            ||
| 78 | * @param Parser $parser  | 
            ||
| 79 | *  | 
            ||
| 80 | * @return string  | 
            ||
| 81 | */  | 
            ||
| 82 | 	public final function renderMap( array $params, Parser $parser ) { | 
            ||
| 100 | |||
| 101 | /**  | 
            ||
| 102 | * Converts the data in the coordinates parameter to JSON-ready objects.  | 
            ||
| 103 | * These get stored in the locations parameter, and the coordinates on gets deleted.  | 
            ||
| 104 | *  | 
            ||
| 105 | * FIXME: complexity  | 
            ||
| 106 | *  | 
            ||
| 107 | * @since 1.0  | 
            ||
| 108 | *  | 
            ||
| 109 | * @param array &$params  | 
            ||
| 110 | * @param Parser $parser  | 
            ||
| 111 | */  | 
            ||
| 112 | 	protected function handleMarkerData( array &$params, Parser $parser ) { | 
            ||
| 154 | |||
| 155 | 	protected function handleShapeData( array &$params, Parser $parserClone ) { | 
            ||
| 181 | |||
| 182 | /**  | 
            ||
| 183 | * FIXME  | 
            ||
| 184 | *  | 
            ||
| 185 | * Temporary hack until the mapping service handling gets a proper refactor  | 
            ||
| 186 | * This kind of JS construction is also rather evil and should not be done at this point  | 
            ||
| 187 | *  | 
            ||
| 188 | * @since 3.0  | 
            ||
| 189 | * @deprecated  | 
            ||
| 190 | *  | 
            ||
| 191 | * @param string[] $layers  | 
            ||
| 192 | *  | 
            ||
| 193 | * @return string[]  | 
            ||
| 194 | */  | 
            ||
| 195 | 	public static function evilOpenLayersHack( $layers ) { | 
            ||
| 234 | |||
| 235 | 	public static function getLayerDependencies( $service, $params ) { | 
            ||
| 266 | |||
| 267 | }  | 
            ||
| 268 | 
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.