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 ( ba89cf...799599 )
by Oleg
02:27
created

Vehicle::createVehicle()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 24

Duplication

Lines 24
Ratio 100 %

Importance

Changes 0
Metric Value
cc 5
nc 5
nop 1
dl 24
loc 24
rs 9.2248
c 0
b 0
f 0
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 View Code Duplication
    public static function getVehicles($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...
79
    {
80
        $response = Route4Me::makeRequst(array(
81
            'url'    => Endpoint::VEHICLE_V4,
82
            'method' => 'GET',
83
            'query'  => array(
84
                'with_pagination'  => isset($params['with_pagination']) ? $params['with_pagination'] : null,
85
                'page'             => isset($params['page']) ? $params['page'] : null,
86
                'perPage'          => isset($params['perPage']) ? $params['perPage'] : null,
87
            )
88
        ));
89
90
        return $response;
91
    }
92
    
93
    public function getRandomVehicleId($page,$perPage)
94
    {
95
        $query['page'] = isset($page) ? $page : 1;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$query was never initialized. Although not strictly required by PHP, it is generally a good practice to add $query = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
96
        $query['perPage'] = isset($perPage) ? $perPage : 10;
97
        $query['with_pagination'] = true;
98
        
99
        $vehicles = $this->getVehicles($query);
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 View Code Duplication
    public function getVehicleByID($vehicleID)
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...
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
        $body = array();
125
        
126
        $vehicle= new Vehicle();
127
        
128
        foreach($params as $key => $value) {
129
            if ($key=="vehicle_id") continue; 
130
            if (property_exists($vehicle, $key)) {
131
                if (isset($params->{$key})) {
132
                    $body[$key] = $params->{$key};
133
                } 
134
            }
135
        }
136
        
137
        $response = Route4Me::makeRequst(array(
138
            'url'    => Endpoint::VEHICLE_V4 . '/' . $vehicleID,
139
            'method' => 'PUT',
140
            'body'   => $body,
141
            'HTTPHEADER'  => 'Content-Type: application/json'
142
        ));
143
144
        return $response;
145
    }
146
    
147 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...
148
    {
149
        $body = array();
150
        
151
        $vehicle= new Vehicle();
152
        
153
        foreach($params as $key => $value) {
154
            if ($key=="vehicle_id") continue; 
155
            if (property_exists($vehicle, $key)) {
156
                if (isset($params->{$key})) {
157
                    $body[$key] = $params->{$key};
158
                } 
159
            }
160
        }
161
        
162
        $response = Route4Me::makeRequst(array(
163
            'url'    => Endpoint::VEHICLE_V4,
164
            'method' => 'POST',
165
            'body'   => $body,
166
            'HTTPHEADER'  => 'Content-Type: application/json'
167
        ));
168
169
        return $response;
170
    }
171
    
172
    public function removeVehicle($params)
173
    {
174
        $vehicleID = isset($params->vehicle_id) ? $params->vehicle_id : null;
175
        
176
        $response = Route4Me::makeRequst(array(
177
            'url'    => Endpoint::VEHICLE_V4 . '/' . $vehicleID,
178
            'method' => 'DELETE',
179
            'HTTPHEADER'  => 'Content-Type: application/json'
180
        ));
181
182
        return $response;
183
    }
184
}
185