@@ -15,6 +15,13 @@ class LookupRequestBuilder extends AbstractBuilder implements BuilderInterface
15
15
*/
16
16
protected $ registration ;
17
17
18
+ /**
19
+ * VIN
20
+ *
21
+ * @var string
22
+ */
23
+ protected $ vin ;
24
+
18
25
protected $ flagsEnum = VehicleLookupFlags::class;
19
26
20
27
/**
@@ -24,7 +31,7 @@ class LookupRequestBuilder extends AbstractBuilder implements BuilderInterface
24
31
*/
25
32
protected $ odometerReadingMiles ;
26
33
27
- protected $ requiredAttributes = [' registration ' ];
34
+ protected $ requiredAttributes = [];
28
35
29
36
/**
30
37
* Get the registration.
@@ -50,6 +57,20 @@ public function setRegistration(string $registration): LookupRequestBuilder
50
57
return $ this ;
51
58
}
52
59
60
+ /**
61
+ * Set the VIN.
62
+ *
63
+ * @param string $vin
64
+ *
65
+ * @return $this
66
+ */
67
+ public function setVin (string $ vin ): LookupRequestBuilder
68
+ {
69
+ $ this ->vin = $ vin ;
70
+
71
+ return $ this ;
72
+ }
73
+
53
74
/**
54
75
* Get the mileage.
55
76
*
@@ -85,6 +106,11 @@ public function validate(): bool
85
106
{
86
107
parent ::validate ();
87
108
109
+ // Require a registration or VIN
110
+ if (empty ($ this ->registration ) && empty ($ this ->vin )) {
111
+ throw new ValidationException ('A registration or VIN must be set. ' );
112
+ }
113
+
88
114
// Validate the odometer status.
89
115
$ requiresOdometerReading = !empty (array_intersect (
90
116
[VehicleLookupFlags::VALUATIONS , VehicleLookupFlags::VEHICLE_METRICS ],
@@ -114,7 +140,8 @@ public function toArray(): array
114
140
$ this ->validate ();
115
141
116
142
return $ this ->filterPrepareOutput ([
117
- 'registration ' => preg_replace ('/\s/ ' , '' , $ this ->registration ),
143
+ 'registration ' => !empty ($ this ->registration ) ? preg_replace ('/\s/ ' , '' , $ this ->registration ) : null ,
144
+ 'vin ' => !empty ($ this ->vin ) ? preg_replace ('/\s/ ' , '' , $ this ->vin ) : null ,
118
145
'odometerReadingMiles ' => $ this ->odometerReadingMiles ,
119
146
] + $ this ->transformFlags ($ this ->flags ));
120
147
}
0 commit comments