Passed
Push — master ( 410874...492133 )
by Nicholas
01:38
created

Vehicle   B

Complexity

Total Complexity 45

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 41
dl 0
loc 120
rs 8.8
c 0
b 0
f 0
wmc 45

12 Methods

Rating   Name   Duplication   Size   Complexity  
A getVehicleByLicensePlate() 0 7 4
A getVehicleByVehicleId() 0 7 3
B getProductByFitment() 0 7 7
A getVehicleTrim() 0 7 5
A getVehicleTrimOption() 0 7 6
A getVehicleModel() 0 8 4
A getVehiclePlusSizes() 0 7 6
A countVIN() 0 7 2
A getVehicleYear() 0 3 1
A __construct() 0 5 1
A getVehicleByVIN() 0 7 3
A getVehicleMake() 0 5 3

How to fix   Complexity   

Complex Class

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
2
3
namespace Nickcheek\Atdconnect\Services;
4
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()
15
	{
16
	    $config = include(realpath(dirname(__FILE__) . '/../config/config.php'));
17
	    $this->location = $config->location;
18
		$this->wsdl = 'http://testws.atdconnect.com/ws/3_4/fitments.wsdl';
19
		
20
	}
21
	
22
	//************************************************
23
    //               Vehicle Service
24
    //************************************************
25
    public static function countVIN(string $vin): self
26
    {
27
    	$count = strlen($vin);
28
    	if($count == 17){
29
	    	return new self($count);	
0 ignored issues
show
Unused Code introduced by
The call to Nickcheek\Atdconnect\Ser...\Vehicle::__construct() has too many arguments starting with $count. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
	    	return /** @scrutinizer ignore-call */ new self($count);	

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
30
    	} else {
31
	    	return new self($count);
32
    	}
33
        
34
    }
35
    
36
    public  function getVehicleYear()
37
    {
38
        return $this->apiCall('getVehicleYear','',$this->wsdl);
39
    }
40
    
41
    public  function getVehicleMake($year)
42
    {	
43
    	try { if (empty($year)) { throw new \Exception("A Vehicle Year Has Not Been Set."); } 
44
    		return $this->apiCall('getVehicleMake',['vehicle' => ['year'=>$year]],$this->wsdl);
45
        } catch (Exception $e) { return $e; }
0 ignored issues
show
Bug introduced by
The type Nickcheek\Atdconnect\Services\Exception was not found. Did you mean Exception? If so, make sure to prefix the type with \.
Loading history...
46
    }
47
48
    public  function getVehicleModel($year,$make)
49
    {	
50
    	
51
    	try {if (empty($year)||empty($make)) {throw new \Exception("A Vehicle Year OR Make Has Not Been Set.");}
52
    	
53
        	return $this->apiCall('getVehicleModel',['vehicle' => ['year'=>$year,'make'=>$make]],$this->wsdl);
54
        
55
        } catch (Exception $e) {return $e;}
56
    }
57
58
    
59
    public  function getVehicleTrim($year,$make,$model)
60
    {
61
    	try {if (empty($year)||empty($make)||empty($model)) {throw new \Exception("A Vehicle Year, Make OR Model Has Not Been Set.");}
62
    	
63
        	return $this->apiCall('getVehicleTrim',['vehicle' => ['year'=>$year,'make'=>$make,'model'=>$model]],$this->wsdl);
64
        
65
        } catch (Exception $e) {return $e;}
66
    }
67
    
68
    public function getVehicleTrimOption($year,$make,$model,$trim)
69
    {
70
    	try {if (empty($year)||empty($make)||empty($model)||empty($trim)) {throw new \Exception("A Vehicle Year, Make OR Model Has Not Been Set.");}
71
    	
72
	    	return $this->apiCall('getVehicleTrimOption',['vehicle' => ['year'=>$year,'make'=>$make,'model'=>$model,'trim'=>$trim]],$this->wsdl);
73
	    	
74
	    } catch (Exception $e) {return $e;}
75
	    
76
    }
77
    
78
    public function getVehiclePlusSizes($year,$make,$model,$trim)
79
    {
80
    	try {if (empty($year)||empty($make)||empty($model)||empty($trim)) {throw new \Exception("A Vehicle Year, Make, Model, or Trim Has Not Been Set.");}
81
    	
82
	    	return $this->apiCall('getVehiclePlusSizes',['vehicle' => ['year'=>$year,'make'=>$make,'model'=>$model,'trim'=>$trim]],$this->wsdl);
83
	    	
84
	    } catch (Exception $e) {return $e;}
85
	    
86
    }
87
    
88
    public function getProductByFitment($year,$make,$model,$trim,$option)
89
    {
90
	    try {if (empty($year)||empty($make)||empty($model)||empty($trim)||empty($option)) {throw new \Exception("A Vehicle value required has not been set.");}
91
    	
92
	    	return $this->apiCall('getProductByFitment',['locationNumber'=>$this->location,'vehicle' => ['year'=>$year,'make'=>$make,'model'=>$model,'trim'=>$trim,'trimOption'=>$option]],$this->wsdl);
93
	    	
94
	    } catch (Exception $e) {return $e;}
95
96
    }
97
    
98
    public function getVehicleByVehicleId($vID)
99
    {
100
	    try {if (empty($vID)) {throw new \Exception("A Vehicle value required has not been set.");}
101
    	
102
	    	return $this->apiCall('getProductByFitment',['locationNumber'=>$this->location,'vehicle' => ['vehicleId'=>$vID]],$this->wsdl);
103
	    	
104
	    } catch (Exception $e) {return $e;}
105
106
    }
107
    
108
    public function getVehicleByLicensePlate($num,$state)
109
    {
110
	    try {if (empty($num)||empty($state)) {throw new \Exception("A Vehicle value required has not been set.");}
111
    	
112
	    	return $this->apiCall('getVehicleByLicensePlate',['licensePlateNumber'=>$num,'licensePlateState' => $state],$this->wsdl);
113
	    	
114
	    } catch (Exception $e) {return $e;}
115
116
    }
117
	
118
	public function getVehicleByVIN($vin)
119
    {
120
	    try {if (empty($vin)) {throw new \Exception("A Vehicle value required has not been set.");}
121
    	
122
	    	return $this->apiCall('getVehicleByVIN',['VIN'=>$vin],$this->wsdl);
123
	    	
124
	    } catch (Exception $e) {return $e;}
125
126
    }
127
 
128
}