Skip to content

Commit 16ec0aa

Browse files
authored
Merge pull request #29 from route4me/code_refactoring_v1.2.9
Code refactoring v1.2.9
2 parents 859c792 + 7e0ef5a commit 16ec0aa

File tree

70 files changed

+106
-979
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+106
-979
lines changed

UnitTestFiles/Test/AddressBookGroupUnitTests.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,14 @@ public function testSearchAddressBookGroups()
189189

190190
$this->assertNotNull($addressBookGroups);
191191
$this->assertTrue(sizeof($addressBookGroups->fields)==3);
192-
$this->assertContains('address_id',$addressBookGroups->fields);
193-
$this->assertContains('address_1',$addressBookGroups->fields);
194-
$this->assertContains('address_group',$addressBookGroups->fields);
192+
$this->assertContains('address_id', $addressBookGroups->fields);
193+
$this->assertContains('address_1', $addressBookGroups->fields);
194+
$this->assertContains('address_group', $addressBookGroups->fields);
195195

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

198198
if (sizeof($addressBookGroups->results)>0) {
199-
$this->assertContains('Louisville', implode (", ", $addressBookGroups->results[0]));
199+
$this->assertContains('Louisville', implode(", ", $addressBookGroups->results[0]));
200200
}
201201
}
202202

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

262262
$this->assertNotNull($groupIds);
263-
$this->assertTrue(in_array($firstGroup->group_id,$groupIds ));
263+
$this->assertTrue(in_array($firstGroup->group_id, $groupIds));
264264
}
265265

266266
public static function tearDownAfterClass()
@@ -281,4 +281,4 @@ public static function tearDownAfterClass()
281281
}
282282
}
283283
}
284-
}
284+
}

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "route4me/route4me-php",
33
"description": "Access Route4Me's logistics-as-a-service API using our PHP SDK",
44
"minimum-stability": "stable",
5-
"version": "1.2.8",
5+
"version": "1.2.9",
66
"authors": [
77
{
88
"name": "Igor Route4Me",

src/Route4Me/ActivityParameters.php

-13
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,6 @@ public function __construct()
3434
Route4Me::setBaseUrl(Endpoint::BASE_URL);
3535
}
3636

37-
public static function fromArray(array $params)
38-
{
39-
$activityparameters = new self();
40-
41-
foreach ($params as $key => $value) {
42-
if (property_exists($activityparameters, $key)) {
43-
$activityparameters->{$key} = $value;
44-
}
45-
}
46-
47-
return $activityparameters;
48-
}
49-
5037
/*
5138
* Get all the activities limited by query parameters.
5239
*/

src/Route4Me/Address.php

-15
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,6 @@ public function __construct()
103103
Route4Me::setBaseUrl(Endpoint::BASE_URL);
104104
}
105105

106-
public static function fromArray(array $params)
107-
{
108-
$address = new self();
109-
110-
foreach ($params as $key => $value) {
111-
if (property_exists($address, $key)) {
112-
$address->{$key} = $value;
113-
} else {
114-
throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key");
115-
}
116-
}
117-
118-
return $address;
119-
}
120-
121106
public static function getAddress($routeId, $addressId)
122107
{
123108
$address = Route4Me::makeRequst([

src/Route4Me/AddressBookGroup.php

+2-15
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,6 @@ public function __construct()
1818
Route4Me::setBaseUrl(Endpoint::BASE_URL);
1919
}
2020

21-
public static function fromArray(array $params)
22-
{
23-
$addressBookGroup = new self();
24-
25-
foreach ($params as $key => $value) {
26-
if (property_exists($addressBookGroup, $key)) {
27-
$addressBookGroup->{$key} = $value;
28-
}
29-
}
30-
31-
return $addressBookGroup;
32-
}
33-
3421
public static function getAddressBookGroup(array $params)
3522
{
3623
$abGroup = Route4Me::makeRequst([
@@ -83,7 +70,7 @@ public static function createAddressBookGroup(array $params)
8370
return $abGroup;
8471
}
8572

86-
public static function searchAddressBookGroups(array $params)
73+
public static function searchAddressBookGroups(array $params)
8774
{
8875
$allBodyFields = ['fields', 'offset', 'limit', 'filter'];
8976

@@ -127,7 +114,7 @@ public static function getRandomAddressBookGroup(array $params)
127114
{
128115
$abGroups = self::getAddressBookGroups($params);
129116

130-
if (isset($abGroups) && sizeof($abGroups>1)) {
117+
if (isset($abGroups) && sizeof($abGroups) > 1) {
131118
$groupsSize = sizeof($abGroups);
132119

133120
$randomGroupIndex = rand(0, $groupsSize - 1);

src/Route4Me/AddressBookLocation.php

-13
Original file line numberDiff line numberDiff line change
@@ -267,19 +267,6 @@ public function __construct()
267267
Route4Me::setBaseUrl(Endpoint::BASE_URL);
268268
}
269269

270-
public static function fromArray(array $params)
271-
{
272-
$addressbooklocation = new self();
273-
274-
foreach ($params as $key => $value) {
275-
if (property_exists($addressbooklocation, $key)) {
276-
$addressbooklocation->{$key} = $value;
277-
}
278-
}
279-
280-
return $addressbooklocation;
281-
}
282-
283270
/**
284271
* @deprecated 1.2.8
285272
* @see \Route4Me\V5\AddressBook\AddressBook::getAddressById()

src/Route4Me/AddressBookLocationSearchResponse.php

+1-16
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,4 @@ class AddressBookLocationSearchResponse
99
public $results=[];
1010
public $total;
1111
public $fields=[];
12-
13-
public static function fromArray(array $params)
14-
{
15-
$ablSearchResponse = new self();
16-
17-
foreach ($params as $key => $value) {
18-
if (property_exists($ablSearchResponse, $key)) {
19-
$ablSearchResponse->{$key} = $value;
20-
} else {
21-
throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key");
22-
}
23-
}
24-
25-
return $ablSearchResponse;
26-
}
27-
}
12+
}

src/Route4Me/AddressNote.php

-16
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,6 @@ class AddressNote extends Common
9797

9898
public function __construct()
9999
{
100-
101-
}
102-
103-
public static function fromArray(array $params)
104-
{
105-
$addressNote = new self();
106-
107-
foreach ($params as $key => $value) {
108-
if (property_exists($addressNote, $key)) {
109-
$addressNote->{$key} = $value;
110-
} else {
111-
throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key");
112-
}
113-
}
114-
115-
return $addressNote;
116100
}
117101

118102
/**

src/Route4Me/AddressNoteResponse.php

+1-16
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,4 @@ class AddressNoteResponse extends Common
1313
public $note_id;
1414
public $upload_id;
1515
public $note;
16-
17-
public static function fromArray(array $params)
18-
{
19-
$addressNoteResponse = new self();
20-
21-
foreach ($params as $key => $value) {
22-
if (property_exists($addressNoteResponse, $key)) {
23-
$addressNoteResponse->{$key} = $value;
24-
} else {
25-
throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key");
26-
}
27-
}
28-
29-
return $addressNoteResponse;
30-
}
31-
}
16+
}

src/Route4Me/AvoidanceZone.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,7 @@ public static function fromArray(array $params)
3232
if (!isset($params['territory'])) {
3333
throw new BadParam('Territory must be provided');
3434
}
35-
36-
$avoidanceZoneParameters = new self();
37-
38-
foreach ($params as $key => $value) {
39-
if (property_exists($avoidanceZoneParameters, $key)) {
40-
$avoidanceZoneParameters->{$key} = $value;
41-
}
42-
}
43-
44-
return $avoidanceZoneParameters;
35+
return parent::fromArray($params);
4536
}
4637

4738
public static function getAvoidanceZone($territory_id)

src/Route4Me/Common.php

+11
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,15 @@ protected function fillFromArray(array $params)
2626
}
2727
}
2828
}
29+
30+
public static function fromArray(array $params)
31+
{
32+
$_this = new static;
33+
foreach ($params as $key => $value) {
34+
if (property_exists($_this, $key)) {
35+
$_this->{$key} = $value;
36+
}
37+
}
38+
return $_this;
39+
}
2940
}

src/Route4Me/CustomNoteType.php

+1-16
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,4 @@ class CustomNoteType extends Common
3737
* Note custom type
3838
*/
3939
public $note_custom_type;
40-
41-
public static function fromArray(array $params)
42-
{
43-
$customNoteType = new self();
44-
45-
foreach ($params as $key => $value) {
46-
if (property_exists($customNoteType, $key)) {
47-
$customNoteType->{$key} = $value;
48-
} else {
49-
throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key");
50-
}
51-
}
52-
53-
return $customNoteType;
54-
}
55-
}
40+
}

src/Route4Me/CustomNoteTypeResponse.php

+1-16
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,4 @@ class CustomNoteTypeResponse extends Common
2929
* @var array
3030
*/
3131
public $note_custom_type_values=[];
32-
33-
public static function fromArray(array $params)
34-
{
35-
$customNoteTypeResponse = new self();
36-
37-
foreach ($params as $key => $value) {
38-
if (property_exists($customNoteTypeResponse, $key)) {
39-
$customNoteTypeResponse->{$key} = $value;
40-
} else {
41-
throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key");
42-
}
43-
}
44-
45-
return $customNoteTypeResponse;
46-
}
47-
}
32+
}

src/Route4Me/Direction.php

+1-14
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,4 @@ class Direction extends Common
2222
* @var DirectionStep[]
2323
*/
2424
public $steps = [];
25-
26-
public static function fromArray(array $params)
27-
{
28-
$thisParams = new self();
29-
30-
foreach ($params as $key => $value) {
31-
if (property_exists($thisParams, $key)) {
32-
$thisParams->{$key} = $value;
33-
}
34-
}
35-
36-
return $thisParams;
37-
}
38-
}
25+
}

src/Route4Me/DirectionLocation.php

+1-14
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,4 @@ class DirectionLocation extends Common
5252
* @var integer
5353
*/
5454
public $error_code;
55-
56-
public static function fromArray(array $params)
57-
{
58-
$thisParams = new self();
59-
60-
foreach ($params as $key => $value) {
61-
if (property_exists($thisParams, $key)) {
62-
$thisParams->{$key} = $value;
63-
}
64-
}
65-
66-
return $thisParams;
67-
}
68-
}
55+
}

src/Route4Me/DirectionStep.php

+1-14
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,4 @@ class DirectionStep extends Common
7070
* @var GeoPoint
7171
*/
7272
public $maneuverPoint;
73-
74-
public static function fromArray(array $params)
75-
{
76-
$thisParams = new self();
77-
78-
foreach ($params as $key => $value) {
79-
if (property_exists($thisParams, $key)) {
80-
$thisParams->{$key} = $value;
81-
}
82-
}
83-
84-
return $thisParams;
85-
}
86-
}
73+
}

src/Route4Me/GeoPoint.php

+1-14
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,4 @@ class GeoPoint extends Common
2222
* @var double
2323
*/
2424
public $lng;
25-
26-
public static function fromArray(array $params)
27-
{
28-
$thisParams = new self();
29-
30-
foreach ($params as $key => $value) {
31-
if (property_exists($thisParams, $key)) {
32-
$thisParams->{$key} = $value;
33-
}
34-
}
35-
36-
return $thisParams;
37-
}
38-
}
25+
}

src/Route4Me/Geocoding.php

-13
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,6 @@ class Geocoding extends Common
1515
public $housenumber;
1616
public $zipcode;
1717

18-
public static function fromArray(array $params)
19-
{
20-
$geocoding = new self();
21-
22-
foreach ($params as $key => $value) {
23-
if (property_exists($geocoding, $key)) {
24-
$geocoding->{$key} = $value;
25-
}
26-
}
27-
28-
return $geocoding;
29-
}
30-
3118
public static function forwardGeocoding($params)
3219
{
3320
$allBodyFields = ['strExportFormat', 'addresses'];

0 commit comments

Comments
 (0)