Passed
Pull Request — master (#72)
by Anatoly
11:33
created
src/Vin.php 2 patches
Indentation   +264 added lines, -264 removed lines patch added patch discarded remove patch
@@ -39,268 +39,268 @@
 block discarded – undo
39 39
 class Vin implements VinInterface
40 40
 {
41 41
 
42
-    /**
43
-     * Regular expression for a VIN parsing/validation (ISO 3779)
44
-     *
45
-     * @var string
46
-     *
47
-     * @link https://www.iso.org/standard/52200.html
48
-     */
49
-    public const REGEX = '/^(?<wmi>[0-9A-HJ-NPR-Z]{3})(?<vds>[0-9A-HJ-NPR-Z]{6})(?<vis>[0-9A-HJ-NPR-Z]{8})$/';
50
-
51
-    /**
52
-     * The VIN value
53
-     *
54
-     * @var string
55
-     */
56
-    private $vin;
57
-
58
-    /**
59
-     * World manufacturer identifier
60
-     *
61
-     * @var string
62
-     */
63
-    private $wmi;
64
-
65
-    /**
66
-     * Vehicle descriptor section
67
-     *
68
-     * @var string
69
-     */
70
-    private $vds;
71
-
72
-    /**
73
-     * Vehicle identifier section
74
-     *
75
-     * @var string
76
-     */
77
-    private $vis;
78
-
79
-    /**
80
-     * Vehicle region
81
-     *
82
-     * @var string|null
83
-     */
84
-    private $region;
85
-
86
-    /**
87
-     * Vehicle country
88
-     *
89
-     * @var string|null
90
-     */
91
-    private $country;
92
-
93
-    /**
94
-     * Vehicle manufacturer
95
-     *
96
-     * @var string|null
97
-     */
98
-    private $manufacturer;
99
-
100
-    /**
101
-     * Vehicle model year
102
-     *
103
-     * @var list<int>
104
-     */
105
-    private $modelYear;
106
-
107
-    /**
108
-     * Constructor of the class
109
-     *
110
-     * @param string $value
111
-     *
112
-     * @throws InvalidArgumentException
113
-     *         If the given value isn't a valid VIN.
114
-     */
115
-    public function __construct(string $value)
116
-    {
117
-        // VIN must be in uppercase...
118
-        $value = strtoupper($value);
119
-
120
-        if (!preg_match(self::REGEX, $value, $match)) {
121
-            throw new InvalidArgumentException(sprintf(
122
-                'The value "%s" is not a valid VIN',
123
-                $value
124
-            ));
125
-        }
126
-
127
-        $this->vin = $value;
128
-        $this->wmi = $match['wmi'];
129
-        $this->vds = $match['vds'];
130
-        $this->vis = $match['vis'];
131
-
132
-        $this->region = $this->determineVehicleRegion();
133
-        $this->country = $this->determineVehicleCountry();
134
-        $this->manufacturer = $this->determineVehicleManufacturer();
135
-        $this->modelYear = $this->determineVehicleModelYear();
136
-    }
137
-
138
-    /**
139
-     * {@inheritdoc}
140
-     */
141
-    public function getVin() : string
142
-    {
143
-        return $this->vin;
144
-    }
145
-
146
-    /**
147
-     * {@inheritdoc}
148
-     */
149
-    public function getWmi() : string
150
-    {
151
-        return $this->wmi;
152
-    }
153
-
154
-    /**
155
-     * {@inheritdoc}
156
-     */
157
-    public function getVds() : string
158
-    {
159
-        return $this->vds;
160
-    }
161
-
162
-    /**
163
-     * {@inheritdoc}
164
-     */
165
-    public function getVis() : string
166
-    {
167
-        return $this->vis;
168
-    }
169
-
170
-    /**
171
-     * {@inheritdoc}
172
-     */
173
-    public function getRegion() : ?string
174
-    {
175
-        return $this->region;
176
-    }
177
-
178
-    /**
179
-     * {@inheritdoc}
180
-     */
181
-    public function getCountry() : ?string
182
-    {
183
-        return $this->country;
184
-    }
185
-
186
-    /**
187
-     * {@inheritdoc}
188
-     */
189
-    public function getManufacturer() : ?string
190
-    {
191
-        return $this->manufacturer;
192
-    }
193
-
194
-    /**
195
-     * {@inheritdoc}
196
-     */
197
-    public function getModelYear() : array
198
-    {
199
-        return $this->modelYear;
200
-    }
201
-
202
-    /**
203
-     * Converts the object to array
204
-     *
205
-     * @return array{
206
-     *           vin: string,
207
-     *           wmi: string,
208
-     *           vds: string,
209
-     *           vis: string,
210
-     *           region: ?string,
211
-     *           country: ?string,
212
-     *           manufacturer: ?string,
213
-     *           modelYear: list<int>,
214
-     *         }
215
-     */
216
-    public function toArray() : array
217
-    {
218
-        return [
219
-            'vin' => $this->vin,
220
-            'wmi' => $this->wmi,
221
-            'vds' => $this->vds,
222
-            'vis' => $this->vis,
223
-            'region' => $this->region,
224
-            'country' => $this->country,
225
-            'manufacturer' => $this->manufacturer,
226
-            'modelYear' => $this->modelYear,
227
-        ];
228
-    }
229
-
230
-    /**
231
-     * Converts the object to string
232
-     *
233
-     * @return string
234
-     */
235
-    public function __toString() : string
236
-    {
237
-        return $this->vin;
238
-    }
239
-
240
-    /**
241
-     * Tries to determine vehicle region
242
-     *
243
-     * @return string|null
244
-     */
245
-    private function determineVehicleRegion() : ?string
246
-    {
247
-        return REGIONS[$this->wmi[0]]['region'] ?? null;
248
-    }
249
-
250
-    /**
251
-     * Tries to determine vehicle country
252
-     *
253
-     * @return string|null
254
-     */
255
-    private function determineVehicleCountry() : ?string
256
-    {
257
-        $countries = REGIONS[$this->wmi[0]]['countries'] ?? null;
258
-        if ($countries === null) {
259
-            return null;
260
-        }
261
-
262
-        foreach ($countries as $chars => $name) {
263
-            // there are keys that consist only of numbers...
264
-            $chars = (string) $chars;
265
-
266
-            if (strpbrk($this->wmi[1], $chars) !== false) {
267
-                return $name;
268
-            }
269
-        }
270
-
271
-        return null;
272
-    }
273
-
274
-    /**
275
-     * Tries to determine vehicle manufacturer
276
-     *
277
-     * @return string|null
278
-     */
279
-    private function determineVehicleManufacturer() : ?string
280
-    {
281
-        return MANUFACTURERS[$this->wmi] ?? MANUFACTURERS[$this->wmi[0] . $this->wmi[1]] ?? null;
282
-    }
283
-
284
-    /**
285
-     * Tries to determine vehicle model year(s)
286
-     *
287
-     * @return list<int>
288
-     */
289
-    private function determineVehicleModelYear() : array
290
-    {
291
-        $comingYear = date('Y') + 1;
292
-        $estimatedYears = [];
293
-
294
-        foreach (YEARS as $year => $char) {
295
-            if ($this->vis[0] === $char) {
296
-                $estimatedYears[] = $year;
297
-            }
298
-
299
-            if ($comingYear === $year) {
300
-                break;
301
-            }
302
-        }
303
-
304
-        return $estimatedYears;
305
-    }
42
+	/**
43
+	 * Regular expression for a VIN parsing/validation (ISO 3779)
44
+	 *
45
+	 * @var string
46
+	 *
47
+	 * @link https://www.iso.org/standard/52200.html
48
+	 */
49
+	public const REGEX = '/^(?<wmi>[0-9A-HJ-NPR-Z]{3})(?<vds>[0-9A-HJ-NPR-Z]{6})(?<vis>[0-9A-HJ-NPR-Z]{8})$/';
50
+
51
+	/**
52
+	 * The VIN value
53
+	 *
54
+	 * @var string
55
+	 */
56
+	private $vin;
57
+
58
+	/**
59
+	 * World manufacturer identifier
60
+	 *
61
+	 * @var string
62
+	 */
63
+	private $wmi;
64
+
65
+	/**
66
+	 * Vehicle descriptor section
67
+	 *
68
+	 * @var string
69
+	 */
70
+	private $vds;
71
+
72
+	/**
73
+	 * Vehicle identifier section
74
+	 *
75
+	 * @var string
76
+	 */
77
+	private $vis;
78
+
79
+	/**
80
+	 * Vehicle region
81
+	 *
82
+	 * @var string|null
83
+	 */
84
+	private $region;
85
+
86
+	/**
87
+	 * Vehicle country
88
+	 *
89
+	 * @var string|null
90
+	 */
91
+	private $country;
92
+
93
+	/**
94
+	 * Vehicle manufacturer
95
+	 *
96
+	 * @var string|null
97
+	 */
98
+	private $manufacturer;
99
+
100
+	/**
101
+	 * Vehicle model year
102
+	 *
103
+	 * @var list<int>
104
+	 */
105
+	private $modelYear;
106
+
107
+	/**
108
+	 * Constructor of the class
109
+	 *
110
+	 * @param string $value
111
+	 *
112
+	 * @throws InvalidArgumentException
113
+	 *         If the given value isn't a valid VIN.
114
+	 */
115
+	public function __construct(string $value)
116
+	{
117
+		// VIN must be in uppercase...
118
+		$value = strtoupper($value);
119
+
120
+		if (!preg_match(self::REGEX, $value, $match)) {
121
+			throw new InvalidArgumentException(sprintf(
122
+				'The value "%s" is not a valid VIN',
123
+				$value
124
+			));
125
+		}
126
+
127
+		$this->vin = $value;
128
+		$this->wmi = $match['wmi'];
129
+		$this->vds = $match['vds'];
130
+		$this->vis = $match['vis'];
131
+
132
+		$this->region = $this->determineVehicleRegion();
133
+		$this->country = $this->determineVehicleCountry();
134
+		$this->manufacturer = $this->determineVehicleManufacturer();
135
+		$this->modelYear = $this->determineVehicleModelYear();
136
+	}
137
+
138
+	/**
139
+	 * {@inheritdoc}
140
+	 */
141
+	public function getVin() : string
142
+	{
143
+		return $this->vin;
144
+	}
145
+
146
+	/**
147
+	 * {@inheritdoc}
148
+	 */
149
+	public function getWmi() : string
150
+	{
151
+		return $this->wmi;
152
+	}
153
+
154
+	/**
155
+	 * {@inheritdoc}
156
+	 */
157
+	public function getVds() : string
158
+	{
159
+		return $this->vds;
160
+	}
161
+
162
+	/**
163
+	 * {@inheritdoc}
164
+	 */
165
+	public function getVis() : string
166
+	{
167
+		return $this->vis;
168
+	}
169
+
170
+	/**
171
+	 * {@inheritdoc}
172
+	 */
173
+	public function getRegion() : ?string
174
+	{
175
+		return $this->region;
176
+	}
177
+
178
+	/**
179
+	 * {@inheritdoc}
180
+	 */
181
+	public function getCountry() : ?string
182
+	{
183
+		return $this->country;
184
+	}
185
+
186
+	/**
187
+	 * {@inheritdoc}
188
+	 */
189
+	public function getManufacturer() : ?string
190
+	{
191
+		return $this->manufacturer;
192
+	}
193
+
194
+	/**
195
+	 * {@inheritdoc}
196
+	 */
197
+	public function getModelYear() : array
198
+	{
199
+		return $this->modelYear;
200
+	}
201
+
202
+	/**
203
+	 * Converts the object to array
204
+	 *
205
+	 * @return array{
206
+	 *           vin: string,
207
+	 *           wmi: string,
208
+	 *           vds: string,
209
+	 *           vis: string,
210
+	 *           region: ?string,
211
+	 *           country: ?string,
212
+	 *           manufacturer: ?string,
213
+	 *           modelYear: list<int>,
214
+	 *         }
215
+	 */
216
+	public function toArray() : array
217
+	{
218
+		return [
219
+			'vin' => $this->vin,
220
+			'wmi' => $this->wmi,
221
+			'vds' => $this->vds,
222
+			'vis' => $this->vis,
223
+			'region' => $this->region,
224
+			'country' => $this->country,
225
+			'manufacturer' => $this->manufacturer,
226
+			'modelYear' => $this->modelYear,
227
+		];
228
+	}
229
+
230
+	/**
231
+	 * Converts the object to string
232
+	 *
233
+	 * @return string
234
+	 */
235
+	public function __toString() : string
236
+	{
237
+		return $this->vin;
238
+	}
239
+
240
+	/**
241
+	 * Tries to determine vehicle region
242
+	 *
243
+	 * @return string|null
244
+	 */
245
+	private function determineVehicleRegion() : ?string
246
+	{
247
+		return REGIONS[$this->wmi[0]]['region'] ?? null;
248
+	}
249
+
250
+	/**
251
+	 * Tries to determine vehicle country
252
+	 *
253
+	 * @return string|null
254
+	 */
255
+	private function determineVehicleCountry() : ?string
256
+	{
257
+		$countries = REGIONS[$this->wmi[0]]['countries'] ?? null;
258
+		if ($countries === null) {
259
+			return null;
260
+		}
261
+
262
+		foreach ($countries as $chars => $name) {
263
+			// there are keys that consist only of numbers...
264
+			$chars = (string) $chars;
265
+
266
+			if (strpbrk($this->wmi[1], $chars) !== false) {
267
+				return $name;
268
+			}
269
+		}
270
+
271
+		return null;
272
+	}
273
+
274
+	/**
275
+	 * Tries to determine vehicle manufacturer
276
+	 *
277
+	 * @return string|null
278
+	 */
279
+	private function determineVehicleManufacturer() : ?string
280
+	{
281
+		return MANUFACTURERS[$this->wmi] ?? MANUFACTURERS[$this->wmi[0] . $this->wmi[1]] ?? null;
282
+	}
283
+
284
+	/**
285
+	 * Tries to determine vehicle model year(s)
286
+	 *
287
+	 * @return list<int>
288
+	 */
289
+	private function determineVehicleModelYear() : array
290
+	{
291
+		$comingYear = date('Y') + 1;
292
+		$estimatedYears = [];
293
+
294
+		foreach (YEARS as $year => $char) {
295
+			if ($this->vis[0] === $char) {
296
+				$estimatedYears[] = $year;
297
+			}
298
+
299
+			if ($comingYear === $year) {
300
+				break;
301
+			}
302
+		}
303
+
304
+		return $estimatedYears;
305
+	}
306 306
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
         }
126 126
 
127 127
         $this->vin = $value;
128
-        $this->wmi = $match['wmi'];
129
-        $this->vds = $match['vds'];
130
-        $this->vis = $match['vis'];
128
+        $this->wmi = $match[ 'wmi' ];
129
+        $this->vds = $match[ 'vds' ];
130
+        $this->vis = $match[ 'vis' ];
131 131
 
132 132
         $this->region = $this->determineVehicleRegion();
133 133
         $this->country = $this->determineVehicleCountry();
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
      */
245 245
     private function determineVehicleRegion() : ?string
246 246
     {
247
-        return REGIONS[$this->wmi[0]]['region'] ?? null;
247
+        return REGIONS[ $this->wmi[ 0 ] ][ 'region' ] ?? null;
248 248
     }
249 249
 
250 250
     /**
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
      */
255 255
     private function determineVehicleCountry() : ?string
256 256
     {
257
-        $countries = REGIONS[$this->wmi[0]]['countries'] ?? null;
257
+        $countries = REGIONS[ $this->wmi[ 0 ] ][ 'countries' ] ?? null;
258 258
         if ($countries === null) {
259 259
             return null;
260 260
         }
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
             // there are keys that consist only of numbers...
264 264
             $chars = (string) $chars;
265 265
 
266
-            if (strpbrk($this->wmi[1], $chars) !== false) {
266
+            if (strpbrk($this->wmi[ 1 ], $chars) !== false) {
267 267
                 return $name;
268 268
             }
269 269
         }
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
      */
279 279
     private function determineVehicleManufacturer() : ?string
280 280
     {
281
-        return MANUFACTURERS[$this->wmi] ?? MANUFACTURERS[$this->wmi[0] . $this->wmi[1]] ?? null;
281
+        return MANUFACTURERS[ $this->wmi ] ?? MANUFACTURERS[ $this->wmi[ 0 ].$this->wmi[ 1 ] ] ?? null;
282 282
     }
283 283
 
284 284
     /**
@@ -289,11 +289,11 @@  discard block
 block discarded – undo
289 289
     private function determineVehicleModelYear() : array
290 290
     {
291 291
         $comingYear = date('Y') + 1;
292
-        $estimatedYears = [];
292
+        $estimatedYears = [ ];
293 293
 
294 294
         foreach (YEARS as $year => $char) {
295
-            if ($this->vis[0] === $char) {
296
-                $estimatedYears[] = $year;
295
+            if ($this->vis[ 0 ] === $char) {
296
+                $estimatedYears[ ] = $year;
297 297
             }
298 298
 
299 299
             if ($comingYear === $year) {
Please login to merge, or discard this patch.
src/VinInterface.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -21,59 +21,59 @@
 block discarded – undo
21 21
 interface VinInterface
22 22
 {
23 23
 
24
-    /**
25
-     * Gets the VIN
26
-     *
27
-     * @return string
28
-     */
29
-    public function getVin() : string;
24
+	/**
25
+	 * Gets the VIN
26
+	 *
27
+	 * @return string
28
+	 */
29
+	public function getVin() : string;
30 30
 
31
-    /**
32
-     * Gets WMI (World Manufacturer Identifier) from the VIN
33
-     *
34
-     * @return string
35
-     */
36
-    public function getWmi() : string;
31
+	/**
32
+	 * Gets WMI (World Manufacturer Identifier) from the VIN
33
+	 *
34
+	 * @return string
35
+	 */
36
+	public function getWmi() : string;
37 37
 
38
-    /**
39
-     * Gets VDS (Vehicle Descriptor Section) from the VIN
40
-     *
41
-     * @return string
42
-     */
43
-    public function getVds() : string;
38
+	/**
39
+	 * Gets VDS (Vehicle Descriptor Section) from the VIN
40
+	 *
41
+	 * @return string
42
+	 */
43
+	public function getVds() : string;
44 44
 
45
-    /**
46
-     * Gets VIS (Vehicle Identifier Section) from the VIN
47
-     *
48
-     * @return string
49
-     */
50
-    public function getVis() : string;
45
+	/**
46
+	 * Gets VIS (Vehicle Identifier Section) from the VIN
47
+	 *
48
+	 * @return string
49
+	 */
50
+	public function getVis() : string;
51 51
 
52
-    /**
53
-     * Gets a region from the VIN
54
-     *
55
-     * @return string|null
56
-     */
57
-    public function getRegion() : ?string;
52
+	/**
53
+	 * Gets a region from the VIN
54
+	 *
55
+	 * @return string|null
56
+	 */
57
+	public function getRegion() : ?string;
58 58
 
59
-    /**
60
-     * Gets a country from the VIN
61
-     *
62
-     * @return string|null
63
-     */
64
-    public function getCountry() : ?string;
59
+	/**
60
+	 * Gets a country from the VIN
61
+	 *
62
+	 * @return string|null
63
+	 */
64
+	public function getCountry() : ?string;
65 65
 
66
-    /**
67
-     * Gets a manufacturer from the VIN
68
-     *
69
-     * @return string|null
70
-     */
71
-    public function getManufacturer() : ?string;
66
+	/**
67
+	 * Gets a manufacturer from the VIN
68
+	 *
69
+	 * @return string|null
70
+	 */
71
+	public function getManufacturer() : ?string;
72 72
 
73
-    /**
74
-     * Gets a model year from the VIN
75
-     *
76
-     * @return list<int>
77
-     */
78
-    public function getModelYear() : array;
73
+	/**
74
+	 * Gets a model year from the VIN
75
+	 *
76
+	 * @return list<int>
77
+	 */
78
+	public function getModelYear() : array;
79 79
 }
Please login to merge, or discard this patch.