Skip to content

Commit

Permalink
Moved function fromArray to base class Common
Browse files Browse the repository at this point in the history
  • Loading branch information
0x000F committed Jun 2, 2023
1 parent 1749c32 commit 7e0ef5a
Show file tree
Hide file tree
Showing 67 changed files with 98 additions and 971 deletions.
13 changes: 0 additions & 13 deletions src/Route4Me/ActivityParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,6 @@ public function __construct()
Route4Me::setBaseUrl(Endpoint::BASE_URL);
}

public static function fromArray(array $params)
{
$activityparameters = new self();

foreach ($params as $key => $value) {
if (property_exists($activityparameters, $key)) {
$activityparameters->{$key} = $value;
}
}

return $activityparameters;
}

/*
* Get all the activities limited by query parameters.
*/
Expand Down
15 changes: 0 additions & 15 deletions src/Route4Me/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,6 @@ public function __construct()
Route4Me::setBaseUrl(Endpoint::BASE_URL);
}

public static function fromArray(array $params)
{
$address = new self();

foreach ($params as $key => $value) {
if (property_exists($address, $key)) {
$address->{$key} = $value;
} else {
throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key");
}
}

return $address;
}

public static function getAddress($routeId, $addressId)
{
$address = Route4Me::makeRequst([
Expand Down
17 changes: 2 additions & 15 deletions src/Route4Me/AddressBookGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ public function __construct()
Route4Me::setBaseUrl(Endpoint::BASE_URL);
}

public static function fromArray(array $params)
{
$addressBookGroup = new self();

foreach ($params as $key => $value) {
if (property_exists($addressBookGroup, $key)) {
$addressBookGroup->{$key} = $value;
}
}

return $addressBookGroup;
}

public static function getAddressBookGroup(array $params)
{
$abGroup = Route4Me::makeRequst([
Expand Down Expand Up @@ -83,7 +70,7 @@ public static function createAddressBookGroup(array $params)
return $abGroup;
}

public static function searchAddressBookGroups(array $params)
public static function searchAddressBookGroups(array $params)
{
$allBodyFields = ['fields', 'offset', 'limit', 'filter'];

Expand Down Expand Up @@ -127,7 +114,7 @@ public static function getRandomAddressBookGroup(array $params)
{
$abGroups = self::getAddressBookGroups($params);

if (isset($abGroups) && sizeof($abGroups>1)) {
if (isset($abGroups) && sizeof($abGroups) > 1) {
$groupsSize = sizeof($abGroups);

$randomGroupIndex = rand(0, $groupsSize - 1);
Expand Down
13 changes: 0 additions & 13 deletions src/Route4Me/AddressBookLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,19 +267,6 @@ public function __construct()
Route4Me::setBaseUrl(Endpoint::BASE_URL);
}

public static function fromArray(array $params)
{
$addressbooklocation = new self();

foreach ($params as $key => $value) {
if (property_exists($addressbooklocation, $key)) {
$addressbooklocation->{$key} = $value;
}
}

return $addressbooklocation;
}

/**
* @deprecated 1.2.8
* @see \Route4Me\V5\AddressBook\AddressBook::getAddressById()
Expand Down
17 changes: 1 addition & 16 deletions src/Route4Me/AddressBookLocationSearchResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,4 @@ class AddressBookLocationSearchResponse
public $results=[];
public $total;
public $fields=[];

public static function fromArray(array $params)
{
$ablSearchResponse = new self();

foreach ($params as $key => $value) {
if (property_exists($ablSearchResponse, $key)) {
$ablSearchResponse->{$key} = $value;
} else {
throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key");
}
}

return $ablSearchResponse;
}
}
}
16 changes: 0 additions & 16 deletions src/Route4Me/AddressNote.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,6 @@ class AddressNote extends Common

public function __construct()
{

}

public static function fromArray(array $params)
{
$addressNote = new self();

foreach ($params as $key => $value) {
if (property_exists($addressNote, $key)) {
$addressNote->{$key} = $value;
} else {
throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key");
}
}

return $addressNote;
}

/**
Expand Down
17 changes: 1 addition & 16 deletions src/Route4Me/AddressNoteResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,4 @@ class AddressNoteResponse extends Common
public $note_id;
public $upload_id;
public $note;

public static function fromArray(array $params)
{
$addressNoteResponse = new self();

foreach ($params as $key => $value) {
if (property_exists($addressNoteResponse, $key)) {
$addressNoteResponse->{$key} = $value;
} else {
throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key");
}
}

return $addressNoteResponse;
}
}
}
11 changes: 1 addition & 10 deletions src/Route4Me/AvoidanceZone.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,7 @@ public static function fromArray(array $params)
if (!isset($params['territory'])) {
throw new BadParam('Territory must be provided');
}

$avoidanceZoneParameters = new self();

foreach ($params as $key => $value) {
if (property_exists($avoidanceZoneParameters, $key)) {
$avoidanceZoneParameters->{$key} = $value;
}
}

return $avoidanceZoneParameters;
return parent::fromArray($params);
}

public static function getAvoidanceZone($territory_id)
Expand Down
11 changes: 11 additions & 0 deletions src/Route4Me/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,15 @@ protected function fillFromArray(array $params)
}
}
}

public static function fromArray(array $params)
{
$_this = new static;
foreach ($params as $key => $value) {
if (property_exists($_this, $key)) {
$_this->{$key} = $value;
}
}
return $_this;
}
}
17 changes: 1 addition & 16 deletions src/Route4Me/CustomNoteType.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,4 @@ class CustomNoteType extends Common
* Note custom type
*/
public $note_custom_type;

public static function fromArray(array $params)
{
$customNoteType = new self();

foreach ($params as $key => $value) {
if (property_exists($customNoteType, $key)) {
$customNoteType->{$key} = $value;
} else {
throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key");
}
}

return $customNoteType;
}
}
}
17 changes: 1 addition & 16 deletions src/Route4Me/CustomNoteTypeResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,4 @@ class CustomNoteTypeResponse extends Common
* @var array
*/
public $note_custom_type_values=[];

public static function fromArray(array $params)
{
$customNoteTypeResponse = new self();

foreach ($params as $key => $value) {
if (property_exists($customNoteTypeResponse, $key)) {
$customNoteTypeResponse->{$key} = $value;
} else {
throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key");
}
}

return $customNoteTypeResponse;
}
}
}
15 changes: 1 addition & 14 deletions src/Route4Me/Direction.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,4 @@ class Direction extends Common
* @var DirectionStep[]
*/
public $steps = [];

public static function fromArray(array $params)
{
$thisParams = new self();

foreach ($params as $key => $value) {
if (property_exists($thisParams, $key)) {
$thisParams->{$key} = $value;
}
}

return $thisParams;
}
}
}
15 changes: 1 addition & 14 deletions src/Route4Me/DirectionLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,4 @@ class DirectionLocation extends Common
* @var integer
*/
public $error_code;

public static function fromArray(array $params)
{
$thisParams = new self();

foreach ($params as $key => $value) {
if (property_exists($thisParams, $key)) {
$thisParams->{$key} = $value;
}
}

return $thisParams;
}
}
}
15 changes: 1 addition & 14 deletions src/Route4Me/DirectionStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,4 @@ class DirectionStep extends Common
* @var GeoPoint
*/
public $maneuverPoint;

public static function fromArray(array $params)
{
$thisParams = new self();

foreach ($params as $key => $value) {
if (property_exists($thisParams, $key)) {
$thisParams->{$key} = $value;
}
}

return $thisParams;
}
}
}
15 changes: 1 addition & 14 deletions src/Route4Me/GeoPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,4 @@ class GeoPoint extends Common
* @var double
*/
public $lng;

public static function fromArray(array $params)
{
$thisParams = new self();

foreach ($params as $key => $value) {
if (property_exists($thisParams, $key)) {
$thisParams->{$key} = $value;
}
}

return $thisParams;
}
}
}
13 changes: 0 additions & 13 deletions src/Route4Me/Geocoding.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ class Geocoding extends Common
public $housenumber;
public $zipcode;

public static function fromArray(array $params)
{
$geocoding = new self();

foreach ($params as $key => $value) {
if (property_exists($geocoding, $key)) {
$geocoding->{$key} = $value;
}
}

return $geocoding;
}

public static function forwardGeocoding($params)
{
$allBodyFields = ['strExportFormat', 'addresses'];
Expand Down
13 changes: 0 additions & 13 deletions src/Route4Me/GeocodingResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,4 @@ class GeocodingResponse extends Common
* @var Route
*/
public $original;

public static function fromArray(array $params)
{
$geocodingResponse = new self();

foreach ($params as $key => $value) {
if (property_exists($geocodingResponse, $key)) {
$geocodingResponse->{$key} = $value;
}
}

return $geocodingResponse;
}
}
Loading

0 comments on commit 7e0ef5a

Please sign in to comment.