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   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 156
Duplicated Lines 8.33 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 17
lcom 1
cbo 2
dl 13
loc 156
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fromArray() 0 10 3
A getVehicles() 0 12 1
A getRandomVehicleId() 0 18 6
A getVehicleByID() 0 9 1
A updateVehicle() 0 15 2
A createVehicle() 13 13 1
A removeVehicle() 0 12 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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