GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 7f01d7...1527b5 )
by Oleg
02:36
created

Vehicle::updateVehicle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
namespace Route4Me;
3
4
use Route4Me\Common;
5
use Route4Me\Enum\Endpoint;
6
7
class Vehicle extends Common
8
{
9
    public $vehicle_id;
10
    public $member_id;
11
    public $is_deleted;
12
    public $vehicle_alias;
13
    public $vehicle_vin;
14
    public $vehicle_reg_state_id;
15
    public $vehicle_reg_country_id;
16
    public $vehicle_license_plate;
17
    public $vehicle_type_id;
18
    public $vehicle_make;
19
    public $vehicle_model_year;
20
    public $vehicle_model;
21
    public $vehicle_year_acquired;
22
    public $vehicle_cost_new;
23
    public $purchased_new;
24
    public $license_start_date;
25
    public $license_end_date;
26
    public $vehicle_axle_count;
27
    public $is_operational;
28
    public $mpg_city;
29
    public $mpg_highway;
30
    public $fuel_type;
31
    public $height_inches;
32
    public $weight_lb;
33
    public $external_telematics_vehicle_id;
34
    public $has_trailer;
35
    public $heightInInches;
36
    public $lengthInInches;
37
    public $widthInInches;
38
    public $maxWeightPerAxleGroupInPounds;
39
    public $numAxles;
40
    public $weightInPounds;
41
    public $HazmatType;
42
    public $LowEmissionZonePref;
43
    public $Use53FootTrailerRouting;
44
    public $UseNationalNetwork;
45
    public $UseTruckRestrictions;
46
    public $AvoidFerries;
47
    public $DividedHighwayAvoidPreference;
48
    public $FreewayAvoidPreference;
49
    public $InternationalBordersOpen;
50
    public $TollRoadUsage;
51
    public $hwy_only;
52
    public $long_combination_vehicle;
53
    public $avoid_highways;
54
    public $side_street_adherence;
55
    public $truck_config;
56
    public $height_metric;
57
    public $length_metric;
58
    public $width_metric;
59
    public $weight_metric;
60
    public $max_weight_per_axle_group_metric;
61
    
62
    public function __construct () 
63
    {
64
        Route4Me::setBaseUrl(Endpoint::WH_BASE_URL);
65
    }
66
    
67
    public static function fromArray(array $params) {
68
        $vehicle= new Vehicle();
69
        foreach($params as $key => $value) {
70
            if (property_exists($vehicle, $key)) {
71
                $vehicle->{$key} = $value;
72
            }
73
        }
74
        
75
        return $vehicle;
76
    }
77
    
78
    public static function getVehicles($params)
79
    {
80
        $allQueryFields = array('with_pagination', 'page', 'perPage');
81
        
82
        $response = Route4Me::makeRequst(array(
83
            'url'    => Endpoint::VEHICLE_V4,
84
            'method' => 'GET',
85
            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params)
86
        ));
87
88
        return $response;
89
    }
90
    
91
    public function getRandomVehicleId($page,$perPage)
92
    {
93
        $params = array(
94
            'page'             => isset($page) ? $page : 1,
95
            'perPage'          => isset($perPage) ? $perPage : 10,
96
            'with_pagination'  => true
97
        );
98
        
99
        $vehicles = $this->getVehicles($params);
100
101
        if (is_null($vehicles)) return null;
102
        if (!isset($vehicles['data'])) return null;
103
        if (sizeof($vehicles['data'])<1) return null;
104
        
105
        $randomIndex = rand(0, sizeof($vehicles['data'])-1);
106
        
107
        return $vehicles['data'][$randomIndex]['vehicle_id'];
108
    }
109
    
110
    public function getVehicleByID($vehicleID)
111
    {
112
        $response = Route4Me::makeRequst(array(
113
            'url'    => Endpoint::VEHICLE_V4 . '/' . $vehicleID,
114
            'method' => 'GET'
115
        ));
116
117
        return $response;
118
    }
119
    
120
    public function updateVehicle($params)
121
    {
122
        $vehicleID = isset($params->vehicle_id) ? $params->vehicle_id : null;
123
        
124
        $allBodyFields = Route4Me::getObjectProperties(new Vehicle(), array('vehicle_id'));
125
        
126
        $response = Route4Me::makeRequst(array(
127
            'url'    => Endpoint::VEHICLE_V4 . '/' . $vehicleID,
128
            'method' => 'PUT',
129
            'body'   => Route4Me::generateRequestParameters($allBodyFields, $params),
130
            'HTTPHEADER'  => 'Content-Type: application/json'
131
        ));
132
133
        return $response;
134
    }
135
    
136 View Code Duplication
    public function createVehicle($params)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
137
    {
138
        $allBodyFields = Route4Me::getObjectProperties(new Vehicle(), array('vehicle_id'));
139
        
140
        $response = Route4Me::makeRequst(array(
141
            'url'    => Endpoint::VEHICLE_V4,
142
            'method' => 'POST',
143
            'body'   => Route4Me::generateRequestParameters($allBodyFields, $params),
144
            'HTTPHEADER'  => 'Content-Type: application/json'
145
        ));
146
147
        return $response;
148
    }
149
    
150
    public function removeVehicle($params)
151
    {
152
        $vehicleID = isset($params->vehicle_id) ? $params->vehicle_id : null;
153
        
154
        $response = Route4Me::makeRequst(array(
155
            'url'    => Endpoint::VEHICLE_V4 . '/' . $vehicleID,
156
            'method' => 'DELETE',
157
            'HTTPHEADER'  => 'Content-Type: application/json'
158
        ));
159
160
        return $response;
161
    }
162
}
163