Total Complexity | 43 |
Total Lines | 110 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like Vehicle often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Vehicle, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
5 | class Vehicle { |
||
6 | use \Nickcheek\Atdconnect\Traits\ApiTrait; |
||
7 | |||
8 | private $location; |
||
9 | private $wsdl; |
||
10 | |||
11 | public $vin; |
||
12 | |||
13 | |||
14 | public function __construct() |
||
19 | |||
20 | } |
||
21 | |||
22 | //************************************************ |
||
23 | // Vehicle Service |
||
24 | //************************************************ |
||
25 | |||
26 | public function getVehicleYear() |
||
27 | { |
||
28 | return $this->apiCall('getVehicleYear','',$this->wsdl); |
||
29 | } |
||
30 | |||
31 | public function getVehicleMake($year) |
||
32 | { |
||
33 | try { if (empty($year)) { throw new \Exception("A Vehicle Year Has Not Been Set."); } |
||
34 | return $this->apiCall('getVehicleMake',['vehicle' => ['year'=>$year]],$this->wsdl); |
||
35 | } catch (Exception $e) { return $e; } |
||
|
|||
36 | } |
||
37 | |||
38 | public function getVehicleModel($year,$make) |
||
39 | { |
||
40 | |||
41 | try {if (empty($year)||empty($make)) {throw new \Exception("A Vehicle Year OR Make Has Not Been Set.");} |
||
42 | |||
43 | return $this->apiCall('getVehicleModel',['vehicle' => ['year'=>$year,'make'=>$make]],$this->wsdl); |
||
44 | |||
45 | } catch (Exception $e) {return $e;} |
||
46 | } |
||
47 | |||
48 | |||
49 | public function getVehicleTrim($year,$make,$model) |
||
50 | { |
||
51 | try {if (empty($year)||empty($make)||empty($model)) {throw new \Exception("A Vehicle Year, Make OR Model Has Not Been Set.");} |
||
52 | |||
53 | return $this->apiCall('getVehicleTrim',['vehicle' => ['year'=>$year,'make'=>$make,'model'=>$model]],$this->wsdl); |
||
54 | |||
55 | } catch (Exception $e) {return $e;} |
||
56 | } |
||
57 | |||
58 | public function getVehicleTrimOption($year,$make,$model,$trim) |
||
59 | { |
||
60 | try {if (empty($year)||empty($make)||empty($model)||empty($trim)) {throw new \Exception("A Vehicle Year, Make OR Model Has Not Been Set.");} |
||
61 | |||
62 | return $this->apiCall('getVehicleTrimOption',['vehicle' => ['year'=>$year,'make'=>$make,'model'=>$model,'trim'=>$trim]],$this->wsdl); |
||
63 | |||
64 | } catch (Exception $e) {return $e;} |
||
65 | |||
66 | } |
||
67 | |||
68 | public function getVehiclePlusSizes($year,$make,$model,$trim) |
||
69 | { |
||
70 | try {if (empty($year)||empty($make)||empty($model)||empty($trim)) {throw new \Exception("A Vehicle Year, Make, Model, or Trim Has Not Been Set.");} |
||
71 | |||
72 | return $this->apiCall('getVehiclePlusSizes',['vehicle' => ['year'=>$year,'make'=>$make,'model'=>$model,'trim'=>$trim]],$this->wsdl); |
||
73 | |||
74 | } catch (Exception $e) {return $e;} |
||
75 | |||
76 | } |
||
77 | |||
78 | public function getProductByFitment($year,$make,$model,$trim,$option) |
||
79 | { |
||
80 | try {if (empty($year)||empty($make)||empty($model)||empty($trim)||empty($option)) {throw new \Exception("A Vehicle value required has not been set.");} |
||
81 | |||
82 | return $this->apiCall('getProductByFitment',['locationNumber'=>$this->location,'vehicle' => ['year'=>$year,'make'=>$make,'model'=>$model,'trim'=>$trim,'trimOption'=>$option]],$this->wsdl); |
||
83 | |||
84 | } catch (Exception $e) {return $e;} |
||
85 | |||
86 | } |
||
87 | |||
88 | public function getVehicleByVehicleId($vID) |
||
89 | { |
||
90 | try {if (empty($vID)) {throw new \Exception("A Vehicle value required has not been set.");} |
||
91 | |||
92 | return $this->apiCall('getProductByFitment',['locationNumber'=>$this->location,'vehicle' => ['vehicleId'=>$vID]],$this->wsdl); |
||
93 | |||
94 | } catch (Exception $e) {return $e;} |
||
95 | |||
96 | } |
||
97 | |||
98 | public function getVehicleByLicensePlate($num,$state) |
||
105 | |||
106 | } |
||
107 | |||
108 | public function getVehicleByVIN($vin) |
||
109 | { |
||
110 | try {if (empty($vin)) {throw new \Exception("A Vehicle value required has not been set.");} |
||
111 | |||
112 | return $this->apiCall('getVehicleByVIN',['VIN'=>$vin],$this->wsdl); |
||
113 | |||
119 | } |