Total Complexity | 43 |
Total Lines | 111 |
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 $vehicleYear; |
||
12 | public $vehicleMake; |
||
13 | public $vehicleModel; |
||
14 | |||
15 | public function __construct() |
||
16 | { |
||
17 | $config = include(realpath(dirname(__FILE__) . '/../config/config.php')); |
||
18 | $this->location = $config->location; |
||
19 | $this->wsdl = 'http://testws.atdconnect.com/ws/3_4/fitments.wsdl'; |
||
20 | |||
21 | } |
||
22 | |||
23 | //************************************************ |
||
24 | // Vehicle Service |
||
25 | //************************************************ |
||
26 | |||
27 | public function getVehicleYear() |
||
28 | { |
||
29 | return $this->apiCall('getVehicleYear','',$this->wsdl); |
||
30 | } |
||
31 | |||
32 | public function getVehicleMake($year) |
||
33 | { |
||
34 | try { if (empty($year)) { throw new \Exception("A Vehicle Year Has Not Been Set."); } |
||
35 | return $this->apiCall('getVehicleMake',['vehicle' => ['year'=>$year]],$this->wsdl); |
||
36 | } catch (Exception $e) { return $e; } |
||
|
|||
37 | } |
||
38 | |||
39 | public function getVehicleModel($year,$make) |
||
40 | { |
||
41 | |||
42 | try {if (empty($year)||empty($make)) {throw new \Exception("A Vehicle Year OR Make Has Not Been Set.");} |
||
43 | |||
44 | return $this->apiCall('getVehicleModel',['vehicle' => ['year'=>$year,'make'=>$make]],$this->wsdl); |
||
45 | |||
46 | } catch (Exception $e) {return $e;} |
||
47 | } |
||
48 | |||
49 | |||
50 | public function getVehicleTrim($year,$make,$model) |
||
51 | { |
||
52 | try {if (empty($year)||empty($make)||empty($model)) {throw new \Exception("A Vehicle Year, Make OR Model Has Not Been Set.");} |
||
53 | |||
54 | return $this->apiCall('getVehicleTrim',['vehicle' => ['year'=>$year,'make'=>$make,'model'=>$model]],$this->wsdl); |
||
55 | |||
56 | } catch (Exception $e) {return $e;} |
||
57 | } |
||
58 | |||
59 | public function getVehicleTrimOption($year,$make,$model,$trim) |
||
60 | { |
||
61 | try {if (empty($year)||empty($make)||empty($model)||empty($trim)) {throw new \Exception("A Vehicle Year, Make OR Model Has Not Been Set.");} |
||
62 | |||
63 | return $this->apiCall('getVehicleTrimOption',['vehicle' => ['year'=>$year,'make'=>$make,'model'=>$model,'trim'=>$trim]],$this->wsdl); |
||
64 | |||
65 | } catch (Exception $e) {return $e;} |
||
66 | |||
67 | } |
||
68 | |||
69 | public function getVehiclePlusSizes($year,$make,$model,$trim) |
||
70 | { |
||
71 | try {if (empty($year)||empty($make)||empty($model)||empty($trim)) {throw new \Exception("A Vehicle Year, Make, Model, or Trim Has Not Been Set.");} |
||
72 | |||
73 | return $this->apiCall('getVehiclePlusSizes',['vehicle' => ['year'=>$year,'make'=>$make,'model'=>$model,'trim'=>$trim]],$this->wsdl); |
||
74 | |||
75 | } catch (Exception $e) {return $e;} |
||
76 | |||
77 | } |
||
78 | |||
79 | public function getProductByFitment($year,$make,$model,$trim,$option) |
||
80 | { |
||
81 | try {if (empty($year)||empty($make)||empty($model)||empty($trim)||empty($option)) {throw new \Exception("A Vehicle value required has not been set.");} |
||
82 | |||
83 | return $this->apiCall('getProductByFitment',['locationNumber'=>$this->location,'vehicle' => ['year'=>$year,'make'=>$make,'model'=>$model,'trim'=>$trim,'trimOption'=>$option]],$this->wsdl); |
||
84 | |||
85 | } catch (Exception $e) {return $e;} |
||
86 | |||
87 | } |
||
88 | |||
89 | public function getVehicleByVehicleId($vID) |
||
90 | { |
||
91 | try {if (empty($vID)) {throw new \Exception("A Vehicle value required has not been set.");} |
||
92 | |||
93 | return $this->apiCall('getProductByFitment',['locationNumber'=>$this->location,'vehicle' => ['vehicleId'=>$vID]],$this->wsdl); |
||
94 | |||
95 | } catch (Exception $e) {return $e;} |
||
96 | |||
97 | } |
||
98 | |||
99 | public function getVehicleByLicensePlate($num,$state) |
||
106 | |||
107 | } |
||
108 | |||
109 | public function getVehicleByVIN($vin) |
||
110 | { |
||
111 | try {if (empty($vin)) {throw new \Exception("A Vehicle value required has not been set.");} |
||
112 | |||
113 | return $this->apiCall('getVehicleByVIN',['VIN'=>$vin],$this->wsdl); |
||
114 | |||
116 | |||
117 | } |
||
123 | } |