Passed
Pull Request — master (#54)
by
unknown
10:01
created
src/Vin.php 2 patches
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -32,223 +32,223 @@
 block discarded – undo
32 32
 class Vin implements VinInterface
33 33
 {
34 34
 
35
-    /**
36
-     * Regular expression for a VIN parsing (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
-     * @var string
44
-     */
45
-    private $vin;
46
-
47
-    /**
48
-     * @var string
49
-     */
50
-    private $wmi;
51
-
52
-    /**
53
-     * @var string
54
-     */
55
-    private $vds;
56
-
57
-    /**
58
-     * @var string
59
-     */
60
-    private $vis;
61
-
62
-    /**
63
-     * @var null|string
64
-     */
65
-    private $region;
66
-
67
-    /**
68
-     * @var null|string
69
-     */
70
-    private $country;
71
-
72
-    /**
73
-     * @var null|string
74
-     */
75
-    private $manufacturer;
76
-
77
-    /**
78
-     * @var int[]
79
-     */
80
-    private $modelYear;
81
-
82
-    /**
83
-     * Constructor of the class
84
-     *
85
-     * @param string $value
86
-     *
87
-     * @throws InvalidArgumentException If the given string is not a valid VIN.
88
-     */
89
-    public function __construct(string $value)
90
-    {
91
-        // The given VIN must be in upper case...
92
-        $value = strtoupper($value);
93
-
94
-        if (! preg_match(self::REGEX, $value, $match)) {
95
-            throw new InvalidArgumentException(
96
-                sprintf('The value "%s" is not a valid VIN', $value)
97
-            );
98
-        }
99
-
100
-        // Base values
101
-        $this->vin = $value;
102
-        $this->wmi = $match['wmi'];
103
-        $this->vds = $match['vds'];
104
-        $this->vis = $match['vis'];
105
-
106
-        // Parsed values
107
-        $this->region = $this->identifyRegion();
108
-        $this->country = $this->identifyCountry();
109
-        $this->manufacturer = $this->identifyManufacturer();
110
-        $this->modelYear = $this->identifyModelYear();
111
-    }
112
-
113
-    /**
114
-     * {@inheritDoc}
115
-     */
116
-    public function getVin() : string
117
-    {
118
-        return $this->vin;
119
-    }
120
-
121
-    /**
122
-     * {@inheritDoc}
123
-     */
124
-    public function getWmi() : string
125
-    {
126
-        return $this->wmi;
127
-    }
128
-
129
-    /**
130
-     * {@inheritDoc}
131
-     */
132
-    public function getVds() : string
133
-    {
134
-        return $this->vds;
135
-    }
136
-
137
-    /**
138
-     * {@inheritDoc}
139
-     */
140
-    public function getVis() : string
141
-    {
142
-        return $this->vis;
143
-    }
144
-
145
-    /**
146
-     * {@inheritDoc}
147
-     */
148
-    public function getRegion() : ?string
149
-    {
150
-        return $this->region;
151
-    }
152
-
153
-    /**
154
-     * {@inheritDoc}
155
-     */
156
-    public function getCountry() : ?string
157
-    {
158
-        return $this->country;
159
-    }
160
-
161
-    /**
162
-     * {@inheritDoc}
163
-     */
164
-    public function getManufacturer() : ?string
165
-    {
166
-        return $this->manufacturer;
167
-    }
168
-
169
-    /**
170
-     * {@inheritDoc}
171
-     */
172
-    public function getModelYear() : array
173
-    {
174
-        return $this->modelYear;
175
-    }
176
-
177
-    /**
178
-     * {@inheritDoc}
179
-     */
180
-    public function toArray() : array
181
-    {
182
-        return [
183
-            'vin' => $this->vin,
184
-            'wmi' => $this->wmi,
185
-            'vds' => $this->vds,
186
-            'vis' => $this->vis,
187
-            'region' => $this->region,
188
-            'country' => $this->country,
189
-            'manufacturer' => $this->manufacturer,
190
-            'modelYear' => $this->modelYear,
191
-        ];
192
-    }
193
-
194
-    /**
195
-     * @return null|string
196
-     */
197
-    private function identifyRegion() : ?string
198
-    {
199
-        // undefined region...
200
-        if (! isset(REGIONS[$this->wmi[0]])) {
201
-            return null;
202
-        }
203
-
204
-        return REGIONS[$this->wmi[0]]['region'] ?? null;
205
-    }
206
-
207
-    /**
208
-     * @return null|string
209
-     */
210
-    private function identifyCountry() : ?string
211
-    {
212
-        // undefined region...
213
-        if (! isset(REGIONS[$this->wmi[0]])) {
214
-            return null;
215
-        }
216
-
217
-        foreach (REGIONS[$this->wmi[0]]['countries'] as $chars => $title) {
218
-            if (! (false === strpbrk($this->wmi[1], (string) $chars))) {
219
-                return $title;
220
-            }
221
-        }
222
-
223
-        return null;
224
-    }
225
-
226
-    /**
227
-     * @return null|string
228
-     */
229
-    private function identifyManufacturer() : ?string
230
-    {
231
-        return MANUFACTURERS[$this->wmi] ?? MANUFACTURERS[$this->wmi[0] . $this->wmi[1]] ?? null;
232
-    }
233
-
234
-    /**
235
-     * @return int[]
236
-     */
237
-    private function identifyModelYear() : array
238
-    {
239
-        $comingYear = (int) date('Y') + 1;
240
-        $certainYears = [];
241
-
242
-        foreach (YEARS as $year => $char) {
243
-            if ($this->vis[0] === $char) {
244
-                $certainYears[] = $year;
245
-            }
246
-
247
-            if ($comingYear === $year) {
248
-                break;
249
-            }
250
-        }
251
-
252
-        return $certainYears;
253
-    }
35
+	/**
36
+	 * Regular expression for a VIN parsing (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
+	 * @var string
44
+	 */
45
+	private $vin;
46
+
47
+	/**
48
+	 * @var string
49
+	 */
50
+	private $wmi;
51
+
52
+	/**
53
+	 * @var string
54
+	 */
55
+	private $vds;
56
+
57
+	/**
58
+	 * @var string
59
+	 */
60
+	private $vis;
61
+
62
+	/**
63
+	 * @var null|string
64
+	 */
65
+	private $region;
66
+
67
+	/**
68
+	 * @var null|string
69
+	 */
70
+	private $country;
71
+
72
+	/**
73
+	 * @var null|string
74
+	 */
75
+	private $manufacturer;
76
+
77
+	/**
78
+	 * @var int[]
79
+	 */
80
+	private $modelYear;
81
+
82
+	/**
83
+	 * Constructor of the class
84
+	 *
85
+	 * @param string $value
86
+	 *
87
+	 * @throws InvalidArgumentException If the given string is not a valid VIN.
88
+	 */
89
+	public function __construct(string $value)
90
+	{
91
+		// The given VIN must be in upper case...
92
+		$value = strtoupper($value);
93
+
94
+		if (! preg_match(self::REGEX, $value, $match)) {
95
+			throw new InvalidArgumentException(
96
+				sprintf('The value "%s" is not a valid VIN', $value)
97
+			);
98
+		}
99
+
100
+		// Base values
101
+		$this->vin = $value;
102
+		$this->wmi = $match['wmi'];
103
+		$this->vds = $match['vds'];
104
+		$this->vis = $match['vis'];
105
+
106
+		// Parsed values
107
+		$this->region = $this->identifyRegion();
108
+		$this->country = $this->identifyCountry();
109
+		$this->manufacturer = $this->identifyManufacturer();
110
+		$this->modelYear = $this->identifyModelYear();
111
+	}
112
+
113
+	/**
114
+	 * {@inheritDoc}
115
+	 */
116
+	public function getVin() : string
117
+	{
118
+		return $this->vin;
119
+	}
120
+
121
+	/**
122
+	 * {@inheritDoc}
123
+	 */
124
+	public function getWmi() : string
125
+	{
126
+		return $this->wmi;
127
+	}
128
+
129
+	/**
130
+	 * {@inheritDoc}
131
+	 */
132
+	public function getVds() : string
133
+	{
134
+		return $this->vds;
135
+	}
136
+
137
+	/**
138
+	 * {@inheritDoc}
139
+	 */
140
+	public function getVis() : string
141
+	{
142
+		return $this->vis;
143
+	}
144
+
145
+	/**
146
+	 * {@inheritDoc}
147
+	 */
148
+	public function getRegion() : ?string
149
+	{
150
+		return $this->region;
151
+	}
152
+
153
+	/**
154
+	 * {@inheritDoc}
155
+	 */
156
+	public function getCountry() : ?string
157
+	{
158
+		return $this->country;
159
+	}
160
+
161
+	/**
162
+	 * {@inheritDoc}
163
+	 */
164
+	public function getManufacturer() : ?string
165
+	{
166
+		return $this->manufacturer;
167
+	}
168
+
169
+	/**
170
+	 * {@inheritDoc}
171
+	 */
172
+	public function getModelYear() : array
173
+	{
174
+		return $this->modelYear;
175
+	}
176
+
177
+	/**
178
+	 * {@inheritDoc}
179
+	 */
180
+	public function toArray() : array
181
+	{
182
+		return [
183
+			'vin' => $this->vin,
184
+			'wmi' => $this->wmi,
185
+			'vds' => $this->vds,
186
+			'vis' => $this->vis,
187
+			'region' => $this->region,
188
+			'country' => $this->country,
189
+			'manufacturer' => $this->manufacturer,
190
+			'modelYear' => $this->modelYear,
191
+		];
192
+	}
193
+
194
+	/**
195
+	 * @return null|string
196
+	 */
197
+	private function identifyRegion() : ?string
198
+	{
199
+		// undefined region...
200
+		if (! isset(REGIONS[$this->wmi[0]])) {
201
+			return null;
202
+		}
203
+
204
+		return REGIONS[$this->wmi[0]]['region'] ?? null;
205
+	}
206
+
207
+	/**
208
+	 * @return null|string
209
+	 */
210
+	private function identifyCountry() : ?string
211
+	{
212
+		// undefined region...
213
+		if (! isset(REGIONS[$this->wmi[0]])) {
214
+			return null;
215
+		}
216
+
217
+		foreach (REGIONS[$this->wmi[0]]['countries'] as $chars => $title) {
218
+			if (! (false === strpbrk($this->wmi[1], (string) $chars))) {
219
+				return $title;
220
+			}
221
+		}
222
+
223
+		return null;
224
+	}
225
+
226
+	/**
227
+	 * @return null|string
228
+	 */
229
+	private function identifyManufacturer() : ?string
230
+	{
231
+		return MANUFACTURERS[$this->wmi] ?? MANUFACTURERS[$this->wmi[0] . $this->wmi[1]] ?? null;
232
+	}
233
+
234
+	/**
235
+	 * @return int[]
236
+	 */
237
+	private function identifyModelYear() : array
238
+	{
239
+		$comingYear = (int) date('Y') + 1;
240
+		$certainYears = [];
241
+
242
+		foreach (YEARS as $year => $char) {
243
+			if ($this->vis[0] === $char) {
244
+				$certainYears[] = $year;
245
+			}
246
+
247
+			if ($comingYear === $year) {
248
+				break;
249
+			}
250
+		}
251
+
252
+		return $certainYears;
253
+	}
254 254
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
         // The given VIN must be in upper case...
92 92
         $value = strtoupper($value);
93 93
 
94
-        if (! preg_match(self::REGEX, $value, $match)) {
94
+        if (!preg_match(self::REGEX, $value, $match)) {
95 95
             throw new InvalidArgumentException(
96 96
                 sprintf('The value "%s" is not a valid VIN', $value)
97 97
             );
@@ -99,9 +99,9 @@  discard block
 block discarded – undo
99 99
 
100 100
         // Base values
101 101
         $this->vin = $value;
102
-        $this->wmi = $match['wmi'];
103
-        $this->vds = $match['vds'];
104
-        $this->vis = $match['vis'];
102
+        $this->wmi = $match[ 'wmi' ];
103
+        $this->vds = $match[ 'vds' ];
104
+        $this->vis = $match[ 'vis' ];
105 105
 
106 106
         // Parsed values
107 107
         $this->region = $this->identifyRegion();
@@ -197,11 +197,11 @@  discard block
 block discarded – undo
197 197
     private function identifyRegion() : ?string
198 198
     {
199 199
         // undefined region...
200
-        if (! isset(REGIONS[$this->wmi[0]])) {
200
+        if (!isset(REGIONS[ $this->wmi[ 0 ] ])) {
201 201
             return null;
202 202
         }
203 203
 
204
-        return REGIONS[$this->wmi[0]]['region'] ?? null;
204
+        return REGIONS[ $this->wmi[ 0 ] ][ 'region' ] ?? null;
205 205
     }
206 206
 
207 207
     /**
@@ -210,12 +210,12 @@  discard block
 block discarded – undo
210 210
     private function identifyCountry() : ?string
211 211
     {
212 212
         // undefined region...
213
-        if (! isset(REGIONS[$this->wmi[0]])) {
213
+        if (!isset(REGIONS[ $this->wmi[ 0 ] ])) {
214 214
             return null;
215 215
         }
216 216
 
217
-        foreach (REGIONS[$this->wmi[0]]['countries'] as $chars => $title) {
218
-            if (! (false === strpbrk($this->wmi[1], (string) $chars))) {
217
+        foreach (REGIONS[ $this->wmi[ 0 ] ][ 'countries' ] as $chars => $title) {
218
+            if (!(false === strpbrk($this->wmi[ 1 ], (string) $chars))) {
219 219
                 return $title;
220 220
             }
221 221
         }
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
      */
229 229
     private function identifyManufacturer() : ?string
230 230
     {
231
-        return MANUFACTURERS[$this->wmi] ?? MANUFACTURERS[$this->wmi[0] . $this->wmi[1]] ?? null;
231
+        return MANUFACTURERS[ $this->wmi ] ?? MANUFACTURERS[ $this->wmi[ 0 ].$this->wmi[ 1 ] ] ?? null;
232 232
     }
233 233
 
234 234
     /**
@@ -237,11 +237,11 @@  discard block
 block discarded – undo
237 237
     private function identifyModelYear() : array
238 238
     {
239 239
         $comingYear = (int) date('Y') + 1;
240
-        $certainYears = [];
240
+        $certainYears = [ ];
241 241
 
242 242
         foreach (YEARS as $year => $char) {
243
-            if ($this->vis[0] === $char) {
244
-                $certainYears[] = $year;
243
+            if ($this->vis[ 0 ] === $char) {
244
+                $certainYears[ ] = $year;
245 245
             }
246 246
 
247 247
             if ($comingYear === $year) {
Please login to merge, or discard this patch.