1
|
|
|
<?php |
2
|
|
|
namespace Route4Me; |
3
|
|
|
|
4
|
|
|
use Route4Me\Common; |
5
|
|
|
use Route4Me\Exception\BadParam; |
6
|
|
|
use Route4Me\Enum\Endpoint; |
7
|
|
|
|
8
|
|
|
class TelematicsVendor extends Common |
9
|
|
|
{ |
10
|
|
|
public $vendor_id; // Telematics Vendor id |
11
|
|
|
public $is_integrated; // If 1, the vendor is integrated in Route4Me |
12
|
|
|
public $page; // starting page |
13
|
|
|
public $per_page; // Vendors per page in a response |
14
|
|
|
public $country; // Country Alpha 2 code |
15
|
|
|
public $feature; // Vendor's feature |
16
|
|
|
public $search; // Searched text |
17
|
|
|
public $vendors; // Comma-delimited list of the vendors IDs. |
18
|
|
|
|
19
|
|
|
public static function fromArray(array $params) { |
20
|
|
|
$vendorsParameters = new TelematicsVendor(); |
21
|
|
|
|
22
|
|
|
foreach ($params as $key => $value) { |
23
|
|
|
if (property_exists($vendorsParameters, $key)) { |
24
|
|
|
$vendorsParameters->{$key} = $value; |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
return $vendorsParameters; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
View Code Duplication |
public static function GetTelematicsVendors($params) { |
|
|
|
|
32
|
|
|
Route4Me::setBaseUrl(Endpoint::TELEMATICS_VENDORS); |
33
|
|
|
|
34
|
|
|
$allQueryFields = array('vendor_id', 'is_integrated', 'page', 'per_page', 'country', 'feature', 'search', 'vendors'); |
35
|
|
|
|
36
|
|
|
$vendors = Route4Me::makeRequst(array( |
37
|
|
|
'url' => "", |
38
|
|
|
'method' => 'GET', |
39
|
|
|
'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
40
|
|
|
)); |
41
|
|
|
|
42
|
|
|
return $vendors; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public static function GetRandomVendorID($offset, $limit) { |
46
|
|
|
$allVendors = self::GetTelematicsVendors(null); |
47
|
|
|
$vendorsNumber = sizeof($allVendors['vendors']); |
48
|
|
|
|
49
|
|
|
if ($vendorsNumber < $limit) { |
50
|
|
|
if ($vendorsNumber > $offset) { |
51
|
|
|
$limit = $vendorsNumber; |
52
|
|
|
} else { |
53
|
|
|
if ($vendorsNumber == $offset) { |
54
|
|
|
return $allVendors['vendors'][$offset]->{'vendor_id'}; |
55
|
|
|
} else { |
56
|
|
|
echo "The vendors numbers are less than offset"; |
57
|
|
|
return null; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$randNumber = rand($offset, $limit); |
63
|
|
|
|
64
|
|
|
return $allVendors['vendors'][$randNumber]['id']; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/* |
68
|
|
|
public static function GetTelematicsVendor($params) { |
69
|
|
|
Route4Me::setBaseUrl(Endpoint::TELEMATICS_VENDORS); |
70
|
|
|
|
71
|
|
|
$allQueryFields = array('vendor_id', 'is_integrated', 'page', 'per_page', 'country', 'feature', 'search', 'vendors'); |
72
|
|
|
|
73
|
|
|
$query = Route4Me::generateRequestParameters($allQueryFields, $params); |
74
|
|
|
|
75
|
|
|
$vendors = Route4Me::makeRequst(array( |
76
|
|
|
'url' => "", |
77
|
|
|
'method' => 'GET', |
78
|
|
|
'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
79
|
|
|
)); |
80
|
|
|
|
81
|
|
|
return $vendors; |
82
|
|
|
} |
83
|
|
|
*/ |
84
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.