Skip to content

Commit

Permalink
[TASK] Optimized some setters.
Browse files Browse the repository at this point in the history
  • Loading branch information
adgrafik committed Oct 19, 2013
1 parent 0c8b111 commit bb0848a
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 65 deletions.
29 changes: 17 additions & 12 deletions Classes/API/Controls/MapTypeControlOptions.php
Expand Up @@ -44,11 +44,20 @@ class MapTypeControlOptions extends AbstractControlOptions {
/**
* Set mapTypeIds
*
* @param array $mapTypeIds
* @param string|array $mapTypeIds
* @return \AdGrafik\GoogleMapsPHP\API\Controls\MapTypeControlOptions
*/
public function setMapTypeIds($mapTypeIds) {

if (!$mapTypeIds) {
$this->mapTypeIds = NULL;
return $this;
}

if (is_array($mapTypeIds) === FALSE) {
$mapTypeIds = explode(',', $mapTypeIds);
}

$this->mapTypeIds = array();

foreach ($mapTypeIds as &$mapTypeId) {
Expand All @@ -73,11 +82,7 @@ public function addMapTypeId($mapTypeId) {
|| $mapTypeId == \AdGrafik\GoogleMapsPHP\API\Map\MapTypeId::SATELLITE
|| $mapTypeId == \AdGrafik\GoogleMapsPHP\API\Map\MapTypeId::TERRAIN) {

$id = new \StdClass();
$id->className = 'MapTypeId';
$id->constant = $mapTypeId;

$this->mapTypeIds[] = $id;
$this->mapTypeIds[] = \AdGrafik\GoogleMapsPHP\Utility\JsonUtility::makeConstant('MapTypeId', $mapTypeId);

} else {
$this->mapTypeIds[] = $mapTypeId;
Expand Down Expand Up @@ -117,9 +122,9 @@ public function getMapTypeIds() {
*/
public function setPosition($position) {

$this->position = new \StdClass();
$this->position->className = 'ControlPosition';
$this->position->constant = $position;
$this->position = ($position === \AdGrafik\GoogleMapsPHP\API\Controls\ControlPosition::TOP_RIGHT)
? NULL
: \AdGrafik\GoogleMapsPHP\Utility\JsonUtility::makeConstant('ControlPosition', $position);

return $this;
}
Expand All @@ -141,9 +146,9 @@ public function getPosition() {
*/
public function setStyle($style) {

$this->style = new \StdClass();
$this->style->className = 'MapTypeControlStyle';
$this->style->constant = $style;
$this->style = ($style === \AdGrafik\GoogleMapsPHP\API\Controls\MapTypeControlStyle::DEFAULT_STYLE)
? NULL
: \AdGrafik\GoogleMapsPHP\Utility\JsonUtility::makeConstant('MapTypeControlStyle', $style);

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/API/Controls/OverviewMapControlOptions.php
Expand Up @@ -38,7 +38,7 @@ class OverviewMapControlOptions extends AbstractControlOptions {
* @return \AdGrafik\GoogleMapsPHP\API\Controls\OverviewMapControlOptions
*/
public function setOpened($opened) {
$this->opened = (boolean) $opened;
$this->opened = (boolean) $opened ?: NULL;
return $this;
}

Expand Down
6 changes: 3 additions & 3 deletions Classes/API/Controls/PanControlOptions.php
Expand Up @@ -39,9 +39,9 @@ class PanControlOptions extends AbstractControlOptions {
*/
public function setPosition($position) {

$this->position = new \StdClass();
$this->position->className = 'ControlPosition';
$this->position->constant = $position;
$this->position = ($position === \AdGrafik\GoogleMapsPHP\API\Controls\ControlPosition::TOP_LEFT)
? NULL
: \AdGrafik\GoogleMapsPHP\Utility\JsonUtility::makeConstant('ControlPosition', $position);

return $this;
}
Expand Down
6 changes: 3 additions & 3 deletions Classes/API/Controls/RotateControlOptions.php
Expand Up @@ -39,9 +39,9 @@ class RotateControlOptions extends AbstractControlOptions {
*/
public function setPosition($position) {

$this->position = new \StdClass();
$this->position->className = 'ControlPosition';
$this->position->constant = $position;
$this->position = ($position === \AdGrafik\GoogleMapsPHP\API\Controls\ControlPosition::TOP_LEFT)
? NULL
: \AdGrafik\GoogleMapsPHP\Utility\JsonUtility::makeConstant('ControlPosition', $position);

return $this;
}
Expand Down
12 changes: 6 additions & 6 deletions Classes/API/Controls/ScaleControlOptions.php
Expand Up @@ -44,9 +44,9 @@ class ScaleControlOptions extends AbstractControlOptions {
*/
public function setPosition($position) {

$this->position = new \StdClass();
$this->position->className = 'ControlPosition';
$this->position->constant = $position;
$this->position = ($position === \AdGrafik\GoogleMapsPHP\API\Controls\ControlPosition::BOTTOM_LEFT)
? NULL
: \AdGrafik\GoogleMapsPHP\Utility\JsonUtility::makeConstant('ControlPosition', $position);

return $this;
}
Expand All @@ -68,9 +68,9 @@ public function getPosition() {
*/
public function setStyle($style) {

$this->style = new \StdClass();
$this->style->className = 'ScaleControlStyle';
$this->style->constant = $style;
$this->style = ($style === \AdGrafik\GoogleMapsPHP\API\Controls\ScaleControlStyle::DEFAULT_STYLE)
? NULL
: \AdGrafik\GoogleMapsPHP\Utility\JsonUtility::makeConstant('ScaleControlStyle', $style);


return $this;
Expand Down
6 changes: 3 additions & 3 deletions Classes/API/Controls/StreetViewAddressControlOptions.php
Expand Up @@ -39,9 +39,9 @@ class StreetViewAddressControlOptions extends AbstractControlOptions {
*/
public function setPosition($position) {

$this->position = new \StdClass();
$this->position->className = 'ControlPosition';
$this->position->constant = $position;
$this->position = ($position === \AdGrafik\GoogleMapsPHP\API\Controls\ControlPosition::TOP_LEFT)
? NULL
: \AdGrafik\GoogleMapsPHP\Utility\JsonUtility::makeConstant('ControlPosition', $position);

return $this;
}
Expand Down
6 changes: 3 additions & 3 deletions Classes/API/Controls/StreetViewControlOptions.php
Expand Up @@ -39,9 +39,9 @@ class StreetViewControlOptions extends AbstractControlOptions {
*/
public function setPosition($position) {

$this->position = new \StdClass();
$this->position->className = 'ControlPosition';
$this->position->constant = $position;
$this->position = ($position === \AdGrafik\GoogleMapsPHP\API\Controls\ControlPosition::TOP_LEFT)
? NULL
: \AdGrafik\GoogleMapsPHP\Utility\JsonUtility::makeConstant('ControlPosition', $position);

return $this;
}
Expand Down
12 changes: 6 additions & 6 deletions Classes/API/Controls/ZoomControlOptions.php
Expand Up @@ -44,9 +44,9 @@ class ZoomControlOptions extends AbstractControlOptions {
*/
public function setPosition($position) {

$this->position = new \StdClass();
$this->position->className = 'ControlPosition';
$this->position->constant = $position;
$this->position = ($position === \AdGrafik\GoogleMapsPHP\API\Controls\ControlPosition::TOP_LEFT)
? NULL
: \AdGrafik\GoogleMapsPHP\Utility\JsonUtility::makeConstant('ControlPosition', $position);

return $this;
}
Expand All @@ -68,9 +68,9 @@ public function getPosition() {
*/
public function setStyle($style) {

$this->style = new \StdClass();
$this->style->className = 'ZoomControlStyle';
$this->style->constant = $style;
$this->style = ($style === \AdGrafik\GoogleMapsPHP\API\Controls\ZoomControlStyle::DEFAULT_STYLE)
? NULL
: \AdGrafik\GoogleMapsPHP\Utility\JsonUtility::makeConstant('ZoomControlStyle', $style);

return $this;
}
Expand Down
10 changes: 4 additions & 6 deletions Classes/API/Drawing/DrawingControlOptions.php
Expand Up @@ -47,9 +47,7 @@ class DrawingControlOptions extends \AdGrafik\GoogleMapsPHP\API\Controls\Abstrac
public function setDrawingModes($drawingModes) {

foreach ($drawingModes as $key => &$drawingMode) {
$this->drawingModes[$key] = new \StdClass();
$this->drawingModes[$key]->className = 'drawing.OverlayType';
$this->drawingModes[$key]->constant = $drawingMode;
$this->drawingModes[$key] = \AdGrafik\GoogleMapsPHP\Utility\JsonUtility::makeConstant('drawing.OverlayType', $drawingMode);
}

return $this;
Expand All @@ -72,9 +70,9 @@ public function getDrawingModes() {
*/
public function setPosition($position) {

$this->position = new \StdClass();
$this->position->className = 'ControlPosition';
$this->position->constant = $position;
$this->position = ($position === \AdGrafik\GoogleMapsPHP\API\Controls\ControlPosition::TOP_LEFT)
? NULL
: \AdGrafik\GoogleMapsPHP\Utility\JsonUtility::makeConstant('ControlPosition', $position);

return $this;
}
Expand Down
44 changes: 22 additions & 22 deletions Classes/API/Map/MapOptions.php
Expand Up @@ -210,7 +210,7 @@ public function __construct(array $options = array()) {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setBackgroundColor($backgroundColor) {
$this->backgroundColor = $backgroundColor;
$this->backgroundColor = $backgroundColor ?: NULL;
return $this;
}

Expand Down Expand Up @@ -257,7 +257,7 @@ public function getCenter() {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setDisableDefaultUI($disableDefaultUI) {
$this->disableDefaultUI = (boolean) $disableDefaultUI;
$this->disableDefaultUI = (boolean) $disableDefaultUI ?: NULL;
return $this;
}

Expand All @@ -277,7 +277,7 @@ public function isDisableDefaultUI() {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setDisableDoubleClickZoom($disableDoubleClickZoom) {
$this->disableDoubleClickZoom = (boolean) $disableDoubleClickZoom;
$this->disableDoubleClickZoom = (boolean) $disableDoubleClickZoom ?: NULL;
return $this;
}

Expand All @@ -297,7 +297,7 @@ public function isDisableDoubleClickZoom() {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setDraggable($draggable) {
$this->draggable = (boolean) $draggable;
$this->draggable = (boolean) $draggable ?: NULL;
return $this;
}

Expand All @@ -317,7 +317,7 @@ public function isDraggable() {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setDraggableCursor($draggableCursor) {
$this->draggableCursor = $draggableCursor;
$this->draggableCursor = $draggableCursor ?: NULL;
return $this;
}

Expand All @@ -337,7 +337,7 @@ public function getDraggableCursor() {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setDraggingCursor($draggingCursor) {
$this->draggingCursor = $draggingCursor;
$this->draggingCursor = $draggingCursor ?: NULL;
return $this;
}

Expand All @@ -357,7 +357,7 @@ public function getDraggingCursor() {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setHeading($heading) {
$this->heading = (integer) $heading;
$this->heading = (integer) $heading ?: NULL;
return $this;
}

Expand All @@ -377,7 +377,7 @@ public function getHeading() {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setKeyboardShortcuts($keyboardShortcuts) {
$this->keyboardShortcuts = (boolean) $keyboardShortcuts;
$this->keyboardShortcuts = (boolean) $keyboardShortcuts ?: NULL;
return $this;
}

Expand All @@ -397,7 +397,7 @@ public function isKeyboardShortcuts() {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setMapMaker($mapMaker) {
$this->mapMaker = (boolean) $mapMaker;
$this->mapMaker = (boolean) $mapMaker ?: NULL;
return $this;
}

Expand All @@ -417,7 +417,7 @@ public function isMapMaker() {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setMapTypeControl($mapTypeControl) {
$this->mapTypeControl = (boolean) $mapTypeControl;
$this->mapTypeControl = (boolean) $mapTypeControl ?: NULL;
return $this;
}

Expand Down Expand Up @@ -488,7 +488,7 @@ public function getMapTypeId() {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setMaxZoom($maxZoom) {
$this->maxZoom = (integer) $maxZoom;
$this->maxZoom = (integer) $maxZoom ?: NULL;
return $this;
}

Expand All @@ -508,7 +508,7 @@ public function getMaxZoom() {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setMinZoom($minZoom) {
$this->minZoom = (integer) $minZoom;
$this->minZoom = (integer) $minZoom ?: NULL;
return $this;
}

Expand All @@ -528,7 +528,7 @@ public function getMinZoom() {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setNoClear($noClear) {
$this->noClear = (boolean) $noClear;
$this->noClear = (boolean) $noClear ?: NULL;
return $this;
}

Expand All @@ -548,7 +548,7 @@ public function isNoClear() {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setOverviewMapControl($overviewMapControl) {
$this->overviewMapControl = (boolean) $overviewMapControl;
$this->overviewMapControl = (boolean) $overviewMapControl ?: NULL;
return $this;
}

Expand Down Expand Up @@ -593,7 +593,7 @@ public function getOverviewMapControlOptions() {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setPanControl($panControl) {
$this->panControl = (boolean) $panControl;
$this->panControl = (boolean) $panControl ?: NULL;
return $this;
}

Expand Down Expand Up @@ -638,7 +638,7 @@ public function getPanControlOptions() {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setRotateControl($rotateControl) {
$this->rotateControl = (boolean) $rotateControl;
$this->rotateControl = (boolean) $rotateControl ?: NULL;
return $this;
}

Expand Down Expand Up @@ -683,7 +683,7 @@ public function getRotateControlOptions() {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setScaleControl($scaleControl) {
$this->scaleControl = (boolean) $scaleControl;
$this->scaleControl = (boolean) $scaleControl ?: NULL;
return $this;
}

Expand Down Expand Up @@ -728,7 +728,7 @@ public function getScaleControlOptions() {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setScrollwheel($scrollwheel) {
$this->scrollwheel = (boolean) $scrollwheel;
$this->scrollwheel = (boolean) $scrollwheel ?: NULL;
return $this;
}

Expand Down Expand Up @@ -768,7 +768,7 @@ public function getStreetView() {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setStreetViewControl($streetViewControl) {
$this->streetViewControl = (boolean) $streetViewControl;
$this->streetViewControl = (boolean) $streetViewControl ?: NULL;
return $this;
}

Expand Down Expand Up @@ -833,7 +833,7 @@ public function getStyles() {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setTilt($tilt) {
$this->tilt = (integer) $tilt;
$this->tilt = (integer) $tilt ?: NULL;
return $this;
}

Expand All @@ -853,7 +853,7 @@ public function getTilt() {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setZoom($zoom) {
$this->zoom = (integer) $zoom;
$this->zoom = (integer) $zoom ?: NULL;
return $this;
}

Expand All @@ -873,7 +873,7 @@ public function getZoom() {
* @return \AdGrafik\GoogleMapsPHP\API\Map\MapOptions
*/
public function setZoomControl($zoomControl) {
$this->zoomControl = (boolean) $zoomControl;
$this->zoomControl = (boolean) $zoomControl ?: NULL;
return $this;
}

Expand Down

0 comments on commit bb0848a

Please sign in to comment.