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