From a8c4e03ab1b976a3fb5853d10dfaf2c5c14d77e7 Mon Sep 17 00:00:00 2001 From: David Molineus Date: Tue, 15 Nov 2016 14:01:48 +0100 Subject: [PATCH] Fix code style issues. --- .../Contao/Leaflet/Dca/LayerCallbacks.php | 7 +-- .../Definition/Layer/OverpassLayer.php | 30 ++---------- .../Mapper/Layer/OverpassLayerMapper.php | 39 ++++++++++----- .../Leaflet/Subscriber/BootSubscriber.php | 47 ++++++++++++------- 4 files changed, 62 insertions(+), 61 deletions(-) diff --git a/src/Netzmacht/Contao/Leaflet/Dca/LayerCallbacks.php b/src/Netzmacht/Contao/Leaflet/Dca/LayerCallbacks.php index 727a474..5831d0b 100644 --- a/src/Netzmacht/Contao/Leaflet/Dca/LayerCallbacks.php +++ b/src/Netzmacht/Contao/Leaflet/Dca/LayerCallbacks.php @@ -72,10 +72,6 @@ class LayerCallbacks extends Callbacks * @var array */ private $amenities; - /** - * @var Manager - */ - private $manager; /** * Construct. @@ -85,7 +81,7 @@ class LayerCallbacks extends Callbacks * @param Translator $translator Translator. * @param array $layers Leaflet layer configuration. * @param array $tileProviders Tile providers. - * @param array $amenities OSM amenities + * @param array $amenities OSM amenities. */ public function __construct( Manager $manager, @@ -102,7 +98,6 @@ class LayerCallbacks extends Callbacks $this->database = $database; $this->layers = $layers; $this->tileProviders = $tileProviders; - $this->manager = $manager; $this->translator = $translator; $this->amenities = $amenities; } diff --git a/src/Netzmacht/Contao/Leaflet/Definition/Layer/OverpassLayer.php b/src/Netzmacht/Contao/Leaflet/Definition/Layer/OverpassLayer.php index cd94ff7..15e8139 100644 --- a/src/Netzmacht/Contao/Leaflet/Definition/Layer/OverpassLayer.php +++ b/src/Netzmacht/Contao/Leaflet/Definition/Layer/OverpassLayer.php @@ -59,28 +59,6 @@ class OverpassLayer extends AbstractLayer implements HasOptions, ConvertsToJavas $this->setOptions($options); } - /** - * Set the debug mode. - * - * @param bool $debug Debug mode. - * - * @return $this - */ - public function setDebug($debug) - { - return $this->setOption('debug', (bool) $debug); - } - - /** - * Get debug mode. - * - * @return bool - */ - public function getDebug() - { - return $this->getOption('debug', false); - } - /** * Set the query. * @@ -96,7 +74,7 @@ class OverpassLayer extends AbstractLayer implements HasOptions, ConvertsToJavas /** * Get query. * - * @return bool + * @return string */ public function getQuery() { @@ -118,7 +96,7 @@ class OverpassLayer extends AbstractLayer implements HasOptions, ConvertsToJavas /** * Get endpoint. * - * @return bool + * @return string */ public function getEndpoint() { @@ -164,7 +142,7 @@ class OverpassLayer extends AbstractLayer implements HasOptions, ConvertsToJavas /** * Get minZoom. * - * @return bool + * @return int */ public function getMinZoom() { @@ -176,7 +154,7 @@ class OverpassLayer extends AbstractLayer implements HasOptions, ConvertsToJavas */ public function encode(Encoder $encoder, $flags = null) { - $buffer = sprintf ( + $buffer = sprintf( '%s = new L.OverPassLayer(%s)%s', $encoder->encodeReference($this), $encoder->encodeArray($this->getOptions(), JSON_FORCE_OBJECT), diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/OverpassLayerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/OverpassLayerMapper.php index 95ccca8..74d9bec 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/OverpassLayerMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/OverpassLayerMapper.php @@ -19,7 +19,7 @@ use Netzmacht\JavascriptBuilder\Type\Expression; use Netzmacht\LeafletPHP\Definition; /** - * Class OverpassLayerMapper + * Class OverpassLayerMapper. * * @package Netzmacht\Contao\Leaflet\Mapper\Layer */ @@ -92,19 +92,11 @@ class OverpassLayerMapper extends AbstractLayerMapper */ protected function buildAmenityIconsMap(Model $model) { - $amenityIconsConfig = deserialize($model->amenityIcons, true); - $amenityIconsMap = []; - foreach ($amenityIconsConfig as $config) { - if (!$config['amenity'] || !$config['icon']) { - continue; - } - - $amenityIconsMap[$config['amenity']] = $config['icon']; - } + $amenityIconsMap = $this->filterAmenityIconsConfig($model->amenityIcons); if ($amenityIconsMap) { - $collection = IconModel::findMultipleByIds(array_unique($amenityIconsMap)); - $icons = []; + $collection = IconModel::findMultipleByIds(array_unique($amenityIconsMap)); + $icons = []; if ($collection) { foreach ($collection as $iconModel) { @@ -121,4 +113,27 @@ class OverpassLayerMapper extends AbstractLayerMapper return $amenityIconsMap; } + + /** + * Filter the amenity icons config. + * + * @param mixed $amenityIconsConfig Raw config from the db. + * + * @return array + */ + private function filterAmenityIconsConfig($amenityIconsConfig) + { + $amenityIconsConfig = deserialize($amenityIconsConfig, true); + $amenityIconsMap = []; + + foreach ($amenityIconsConfig as $config) { + if (!$config['amenity'] || !$config['icon']) { + continue; + } + + $amenityIconsMap[$config['amenity']] = $config['icon']; + } + + return $amenityIconsMap; + } } diff --git a/src/Netzmacht/Contao/Leaflet/Subscriber/BootSubscriber.php b/src/Netzmacht/Contao/Leaflet/Subscriber/BootSubscriber.php index 57b5cb7..323d325 100644 --- a/src/Netzmacht/Contao/Leaflet/Subscriber/BootSubscriber.php +++ b/src/Netzmacht/Contao/Leaflet/Subscriber/BootSubscriber.php @@ -25,6 +25,7 @@ use Netzmacht\Contao\Leaflet\Model\IconModel; use Netzmacht\Contao\Toolkit\Boot\Event\InitializeSystemEvent; use Netzmacht\Contao\Toolkit\DependencyInjection\Services; use Netzmacht\LeafletPHP\Assets; +use Netzmacht\LeafletPHP\Definition\Type\Icon; use Netzmacht\LeafletPHP\Definition\Type\ImageIcon; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -218,23 +219,7 @@ class BootSubscriber implements EventSubscriberInterface 'options' => $icon->getOptions(), ); - foreach ($icon::getRequiredLibraries() as $library) { - if (!isset($this->libraries[$library])) { - continue; - } - - $assets = $this->libraries[$library]; - - if (!empty($assets['css'])) { - list ($source, $type) = (array) $assets['css']; - $this->assets->addStylesheet($source, $type ?: Assets::TYPE_FILE); - } - - if (!empty($assets['javascript'])) { - list ($source, $type) = (array) $assets['javascript']; - $this->assets->addJavascript($source, $type ?: Assets::TYPE_FILE); - } - } + $this->loadIconsLibraries($icon); } if ($icons) { @@ -266,4 +251,32 @@ class BootSubscriber implements EventSubscriberInterface return new $mapper; } + + /** + * Load all libraries for an icon. + * + * @param Icon $icon Icon definition + * + * @return void. + */ + protected function loadIconsLibraries($icon) + { + foreach ($icon::getRequiredLibraries() as $library) { + if (!isset($this->libraries[$library])) { + continue; + } + + $assets = $this->libraries[$library]; + + if (!empty($assets['css'])) { + list ($source, $type) = (array)$assets['css']; + $this->assets->addStylesheet($source, $type ?: Assets::TYPE_FILE); + } + + if (!empty($assets['javascript'])) { + list ($source, $type) = (array)$assets['javascript']; + $this->assets->addJavascript($source, $type ?: Assets::TYPE_FILE); + } + } + } }