Skip to content

Commit

Permalink
Merge pull request #29 from route4me/code_refactoring_v1.2.9
Browse files Browse the repository at this point in the history
Code refactoring v1.2.9
  • Loading branch information
h2rd authored Jun 18, 2023
2 parents 859c792 + 7e0ef5a commit 16ec0aa
Show file tree
Hide file tree
Showing 70 changed files with 106 additions and 979 deletions.
12 changes: 6 additions & 6 deletions UnitTestFiles/Test/AddressBookGroupUnitTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ public function testSearchAddressBookGroups()

$this->assertNotNull($addressBookGroups);
$this->assertTrue(sizeof($addressBookGroups->fields)==3);
$this->assertContains('address_id',$addressBookGroups->fields);
$this->assertContains('address_1',$addressBookGroups->fields);
$this->assertContains('address_group',$addressBookGroups->fields);
$this->assertContains('address_id', $addressBookGroups->fields);
$this->assertContains('address_1', $addressBookGroups->fields);
$this->assertContains('address_group', $addressBookGroups->fields);

$this->assertNotNull($addressBookGroups->results);

if (sizeof($addressBookGroups->results)>0) {
$this->assertContains('Louisville', implode (", ", $addressBookGroups->results[0]));
$this->assertContains('Louisville', implode(", ", $addressBookGroups->results[0]));
}
}

Expand Down Expand Up @@ -260,7 +260,7 @@ public function testGetAddressBookGroupIdByName()
$groupIds = AddressBookGroup::getAddressBookGroupIdByName($firstGroup->group_name);

$this->assertNotNull($groupIds);
$this->assertTrue(in_array($firstGroup->group_id,$groupIds ));
$this->assertTrue(in_array($firstGroup->group_id, $groupIds));
}

public static function tearDownAfterClass()
Expand All @@ -281,4 +281,4 @@ public static function tearDownAfterClass()
}
}
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "route4me/route4me-php",
"description": "Access Route4Me's logistics-as-a-service API using our PHP SDK",
"minimum-stability": "stable",
"version": "1.2.8",
"version": "1.2.9",
"authors": [
{
"name": "Igor Route4Me",
Expand Down
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
Loading

0 comments on commit 16ec0aa

Please sign in to comment.