Skip to content

Commit 045b1b8

Browse files
authored
Merge pull request #56 from sunrise-php/release/v1.1.0
v1.1.0
2 parents ebee1fe + f44e825 commit 045b1b8

File tree

9 files changed

+124
-50
lines changed

9 files changed

+124
-50
lines changed

.circleci/config.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# PHP CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-php/ for more details
4+
#
5+
version: 2
6+
jobs:
7+
php71:
8+
docker:
9+
- image: circleci/php:7.1-cli-node-browsers
10+
steps:
11+
- checkout
12+
- run: php -v
13+
- run: composer install --no-interaction --prefer-source --no-suggest
14+
- run: php vendor/bin/phpunit --colors=always
15+
php72:
16+
docker:
17+
- image: circleci/php:7.2-cli-node-browsers
18+
steps:
19+
- checkout
20+
- run: php -v
21+
- run: composer install --no-interaction --prefer-source --no-suggest
22+
- run: php vendor/bin/phpunit --colors=always
23+
php73:
24+
docker:
25+
- image: circleci/php:7.3-cli-node-browsers
26+
steps:
27+
- checkout
28+
- run: php -v
29+
- run: composer install --no-interaction --prefer-source --no-suggest
30+
- run: php vendor/bin/phpunit --colors=always
31+
php74:
32+
docker:
33+
- image: circleci/php:7.4-cli-node-browsers
34+
steps:
35+
- checkout
36+
- run: php -v
37+
- run: composer install --no-interaction --prefer-source --no-suggest
38+
- run: php vendor/bin/phpunit --colors=always
39+
php80:
40+
docker:
41+
- image: circleci/php:8.0-cli-node-browsers
42+
steps:
43+
- checkout
44+
- run: php -v
45+
- run: composer install --no-interaction --prefer-source --no-suggest
46+
- run: php vendor/bin/phpunit --colors=always
47+
workflows:
48+
version: 2
49+
build:
50+
jobs:
51+
- php71
52+
- php72
53+
- php73
54+
- php74
55+
- php80

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.php_cs.cache
2+
.phpunit.result.cache
23
composer.lock
34
coverage.xml
5+
phpbench.json
46
phpcs.xml
57
phpunit.xml
68
vendor/

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ matrix:
55
- php: 7.1
66
- php: 7.2
77
- php: 7.3
8+
- php: 7.4
9+
- php: nightly
810
fast_finish: true
911

1012
before_install:

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 Anatoly Nekhay
3+
Copyright (c) 2018 Sunrise // PHP
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
## Sunrise // Simple VIN decoder for PHP 7.1+ based on ISO-3779
1+
## Simple VIN decoder for PHP 7.1+ (incl. PHP 8) based on ISO-3779
22

33
[![Gitter](https://badges.gitter.im/sunrise-php/support.png)](https://gitter.im/sunrise-php/support)
4-
[![Build Status](https://scrutinizer-ci.com/g/sunrise-php/vin/badges/build.png?b=master)](https://scrutinizer-ci.com/g/sunrise-php/vin/build-status/master)
5-
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/sunrise-php/vin/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/sunrise-php/vin/?branch=master)
4+
[![Build Status](https://circleci.com/gh/sunrise-php/vin.svg?style=shield)](https://circleci.com/gh/sunrise-php/vin)
65
[![Code Coverage](https://scrutinizer-ci.com/g/sunrise-php/vin/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/sunrise-php/vin/?branch=master)
7-
[![Latest Stable Version](https://img.shields.io/packagist/v/sunrise/vin.svg?label=version)](https://packagist.org/packages/sunrise/vin)
6+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/sunrise-php/vin/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/sunrise-php/vin/?branch=master)
87
[![Total Downloads](https://img.shields.io/packagist/dt/sunrise/vin.svg?label=downloads)](https://packagist.org/packages/sunrise/vin)
8+
[![Latest Stable Version](https://img.shields.io/packagist/v/sunrise/vin.svg?label=version)](https://packagist.org/packages/sunrise/vin)
99
[![License](https://img.shields.io/packagist/l/sunrise/vin.svg?label=license)](https://packagist.org/packages/sunrise/vin)
1010

1111
## Installation
@@ -23,7 +23,7 @@ use Sunrise\Vin\Vin;
2323
try {
2424
$vin = new Vin('WVWZZZ1KZ6W612305');
2525
} catch (InvalidArgumentException $e) {
26-
// It's not a valid VIN
26+
// It isn't a valid VIN...
2727
}
2828

2929
$vin->getVin(); // returns "WVWZZZ1KZ6W612305"

composer.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{
22
"name": "sunrise/vin",
33
"homepage": "https://github.com/sunrise-php/vin",
4-
"description": "Sunrise // Simple VIN decoder for PHP 7.1+ based on ISO-3779",
4+
"description": "Simple VIN decoder for PHP 7.1+ based on ISO-3779",
55
"license": "MIT",
66
"keywords": [
77
"fenric",
88
"sunrise",
99
"vin",
1010
"decoder",
11-
"iso-3779"
11+
"iso-3779",
12+
"php7",
13+
"php8"
1214
],
1315
"authors": [
1416
{
@@ -28,11 +30,10 @@
2830
}
2931
],
3032
"require": {
31-
"php": "^7.1"
33+
"php": "^7.1|^8.0"
3234
},
3335
"require-dev": {
34-
"phpunit/phpunit": "7.5.13",
35-
"phpunit/php-code-coverage": "6.1.4",
36+
"phpunit/phpunit": "7.5.20|9.5.0",
3637
"sunrise/coding-standard": "1.0.0"
3738
},
3839
"autoload": {
@@ -47,8 +48,8 @@
4748
},
4849
"scripts": {
4950
"test": [
50-
"phpcs",
51-
"phpunit --colors=always --coverage-text"
51+
"phpunit --colors=always --coverage-text",
52+
"phpcs"
5253
]
5354
}
5455
}

phpunit.xml.dist

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?xml version="1.0"?>
2-
<phpunit colors="true">
2+
<phpunit colors="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage>
4+
<include>
5+
<directory>./src</directory>
6+
</include>
7+
</coverage>
38
<testsuites>
49
<testsuite name="Sunrise VIN Test Suite">
510
<directory>./tests/</directory>
611
</testsuite>
712
</testsuites>
8-
<filter>
9-
<whitelist>
10-
<directory>./src</directory>
11-
</whitelist>
12-
</filter>
1313
</phpunit>

src/Vin.php

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,48 +33,64 @@ class Vin implements VinInterface
3333
{
3434

3535
/**
36-
* Regular expression for a VIN parsing (ISO 3779)
36+
* Regular expression for a VIN parsing/validation (ISO 3779)
3737
*
3838
* @var string
3939
*/
4040
public const REGEX = '/^(?<wmi>[0-9A-HJ-NPR-Z]{3})(?<vds>[0-9A-HJ-NPR-Z]{6})(?<vis>[0-9A-HJ-NPR-Z]{8})$/';
4141

4242
/**
43+
* The VIN code
44+
*
4345
* @var string
4446
*/
4547
private $vin;
4648

4749
/**
50+
* World manufacturer identifier
51+
*
4852
* @var string
4953
*/
5054
private $wmi;
5155

5256
/**
57+
* Vehicle descriptor section
58+
*
5359
* @var string
5460
*/
5561
private $vds;
5662

5763
/**
64+
* Vehicle identifier section
65+
*
5866
* @var string
5967
*/
6068
private $vis;
6169

6270
/**
71+
* Vehicle region
72+
*
6373
* @var null|string
6474
*/
6575
private $region;
6676

6777
/**
78+
* Vehicle country
79+
*
6880
* @var null|string
6981
*/
7082
private $country;
7183

7284
/**
85+
* Vehicle manufacturer
86+
*
7387
* @var null|string
7488
*/
7589
private $manufacturer;
7690

7791
/**
92+
* Vehicle model year
93+
*
7894
* @var int[]
7995
*/
8096
private $modelYear;
@@ -91,7 +107,7 @@ public function __construct(string $value)
91107
// The given VIN must be in upper case...
92108
$value = strtoupper($value);
93109

94-
if (! preg_match(self::REGEX, $value, $match)) {
110+
if (!preg_match(self::REGEX, $value, $match)) {
95111
throw new InvalidArgumentException(
96112
sprintf('The value "%s" is not a valid VIN', $value)
97113
);
@@ -104,10 +120,10 @@ public function __construct(string $value)
104120
$this->vis = $match['vis'];
105121

106122
// Parsed values
107-
$this->region = $this->identifyRegion();
108-
$this->country = $this->identifyCountry();
109-
$this->manufacturer = $this->identifyManufacturer();
110-
$this->modelYear = $this->identifyModelYear();
123+
$this->region = $this->determineRegion();
124+
$this->country = $this->determineCountry();
125+
$this->manufacturer = $this->determineManufacturer();
126+
$this->modelYear = $this->determineModelYear();
111127
}
112128

113129
/**
@@ -175,7 +191,9 @@ public function getModelYear() : array
175191
}
176192

177193
/**
178-
* {@inheritDoc}
194+
* Converts the object to array
195+
*
196+
* @return array
179197
*/
180198
public function toArray() : array
181199
{
@@ -192,63 +210,66 @@ public function toArray() : array
192210
}
193211

194212
/**
213+
* Tries to determine vehicle region
214+
*
195215
* @return null|string
196216
*/
197-
private function identifyRegion() : ?string
217+
private function determineRegion() : ?string
198218
{
199-
// undefined region...
200-
if (! isset(REGIONS[$this->wmi[0]])) {
201-
return null;
202-
}
203-
204219
return REGIONS[$this->wmi[0]]['region'] ?? null;
205220
}
206221

207222
/**
223+
* Tries to determine vehicle country
224+
*
208225
* @return null|string
209226
*/
210-
private function identifyCountry() : ?string
227+
private function determineCountry() : ?string
211228
{
212-
// undefined region...
213-
if (! isset(REGIONS[$this->wmi[0]])) {
229+
$countries = REGIONS[$this->wmi[0]]['countries'] ?? null;
230+
if (null === $countries) {
214231
return null;
215232
}
216233

217-
foreach (REGIONS[$this->wmi[0]]['countries'] as $chars => $title) {
218-
if (! (false === strpbrk($this->wmi[1], (string) $chars))) {
219-
return $title;
234+
foreach ($countries as $chars => $name) {
235+
if (!(false === strpbrk($this->wmi[1], (string) $chars))) {
236+
return $name;
220237
}
221238
}
222239

223240
return null;
224241
}
225242

226243
/**
244+
* Tries to determine vehicle manufacturer
245+
*
227246
* @return null|string
228247
*/
229-
private function identifyManufacturer() : ?string
248+
private function determineManufacturer() : ?string
230249
{
231250
return MANUFACTURERS[$this->wmi] ?? MANUFACTURERS[$this->wmi[0] . $this->wmi[1]] ?? null;
232251
}
233252

234253
/**
254+
* Tries to determine vehicle model year(s)
255+
*
235256
* @return int[]
236257
*/
237-
private function identifyModelYear() : array
258+
private function determineModelYear() : array
238259
{
239260
$comingYear = (int) date('Y') + 1;
240-
$certainYears = [];
261+
$estimatedYears = [];
241262

242263
foreach (YEARS as $year => $char) {
243264
if ($this->vis[0] === $char) {
244-
$certainYears[] = $year;
265+
$estimatedYears[] = $year;
245266
}
246267

247268
if ($comingYear === $year) {
248269
break;
249270
}
250271
}
251272

252-
return $certainYears;
273+
return $estimatedYears;
253274
}
254275
}

src/VinInterface.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,4 @@ public function getManufacturer() : ?string;
9696
* @since 1.0.13
9797
*/
9898
public function getModelYear() : array;
99-
100-
/**
101-
* Converts the VIN to array
102-
*
103-
* @return array
104-
*/
105-
public function toArray() : array;
10699
}

0 commit comments

Comments
 (0)