diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..dd89dfb --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,55 @@ +# PHP CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-php/ for more details +# +version: 2 +jobs: + php71: + docker: + - image: circleci/php:7.1-cli-node-browsers + steps: + - checkout + - run: php -v + - run: composer install --no-interaction --prefer-source --no-suggest + - run: php vendor/bin/phpunit --colors=always + php72: + docker: + - image: circleci/php:7.2-cli-node-browsers + steps: + - checkout + - run: php -v + - run: composer install --no-interaction --prefer-source --no-suggest + - run: php vendor/bin/phpunit --colors=always + php73: + docker: + - image: circleci/php:7.3-cli-node-browsers + steps: + - checkout + - run: php -v + - run: composer install --no-interaction --prefer-source --no-suggest + - run: php vendor/bin/phpunit --colors=always + php74: + docker: + - image: circleci/php:7.4-cli-node-browsers + steps: + - checkout + - run: php -v + - run: composer install --no-interaction --prefer-source --no-suggest + - run: php vendor/bin/phpunit --colors=always + php80: + docker: + - image: circleci/php:8.0-cli-node-browsers + steps: + - checkout + - run: php -v + - run: composer install --no-interaction --prefer-source --no-suggest + - run: php vendor/bin/phpunit --colors=always +workflows: + version: 2 + build: + jobs: + - php71 + - php72 + - php73 + - php74 + - php80 diff --git a/.gitignore b/.gitignore index 002c154..86bfd55 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ .php_cs.cache +.phpunit.result.cache composer.lock coverage.xml +phpbench.json phpcs.xml phpunit.xml vendor/ diff --git a/.travis.yml b/.travis.yml index dde67ac..b0e5e8d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,8 @@ matrix: - php: 7.1 - php: 7.2 - php: 7.3 + - php: 7.4 + - php: nightly fast_finish: true before_install: diff --git a/LICENSE b/LICENSE index 5786b11..19aa2e3 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Anatoly Nekhay +Copyright (c) 2018 Sunrise // PHP Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 2d639b2..b77b6f1 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -## Sunrise // Simple VIN decoder for PHP 7.1+ based on ISO-3779 +## Simple VIN decoder for PHP 7.1+ (incl. PHP 8) based on ISO-3779 [![Gitter](https://badges.gitter.im/sunrise-php/support.png)](https://gitter.im/sunrise-php/support) -[![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) -[![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) +[![Build Status](https://circleci.com/gh/sunrise-php/vin.svg?style=shield)](https://circleci.com/gh/sunrise-php/vin) [![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) -[![Latest Stable Version](https://img.shields.io/packagist/v/sunrise/vin.svg?label=version)](https://packagist.org/packages/sunrise/vin) +[![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) [![Total Downloads](https://img.shields.io/packagist/dt/sunrise/vin.svg?label=downloads)](https://packagist.org/packages/sunrise/vin) +[![Latest Stable Version](https://img.shields.io/packagist/v/sunrise/vin.svg?label=version)](https://packagist.org/packages/sunrise/vin) [![License](https://img.shields.io/packagist/l/sunrise/vin.svg?label=license)](https://packagist.org/packages/sunrise/vin) ## Installation @@ -23,7 +23,7 @@ use Sunrise\Vin\Vin; try { $vin = new Vin('WVWZZZ1KZ6W612305'); } catch (InvalidArgumentException $e) { - // It's not a valid VIN + // It isn't a valid VIN... } $vin->getVin(); // returns "WVWZZZ1KZ6W612305" diff --git a/composer.json b/composer.json index daed65f..4dfe8bb 100644 --- a/composer.json +++ b/composer.json @@ -1,14 +1,16 @@ { "name": "sunrise/vin", "homepage": "https://github.com/sunrise-php/vin", - "description": "Sunrise // Simple VIN decoder for PHP 7.1+ based on ISO-3779", + "description": "Simple VIN decoder for PHP 7.1+ based on ISO-3779", "license": "MIT", "keywords": [ "fenric", "sunrise", "vin", "decoder", - "iso-3779" + "iso-3779", + "php7", + "php8" ], "authors": [ { @@ -28,11 +30,10 @@ } ], "require": { - "php": "^7.1" + "php": "^7.1|^8.0" }, "require-dev": { - "phpunit/phpunit": "7.5.13", - "phpunit/php-code-coverage": "6.1.4", + "phpunit/phpunit": "7.5.20|9.5.0", "sunrise/coding-standard": "1.0.0" }, "autoload": { @@ -47,8 +48,8 @@ }, "scripts": { "test": [ - "phpcs", - "phpunit --colors=always --coverage-text" + "phpunit --colors=always --coverage-text", + "phpcs" ] } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 069443d..2707d57 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,13 +1,13 @@ - + + + + ./src + + ./tests/ - - - ./src - - diff --git a/src/Vin.php b/src/Vin.php index 4c06bd8..2fdf73a 100644 --- a/src/Vin.php +++ b/src/Vin.php @@ -33,48 +33,64 @@ class Vin implements VinInterface { /** - * Regular expression for a VIN parsing (ISO 3779) + * Regular expression for a VIN parsing/validation (ISO 3779) * * @var string */ public const REGEX = '/^(?[0-9A-HJ-NPR-Z]{3})(?[0-9A-HJ-NPR-Z]{6})(?[0-9A-HJ-NPR-Z]{8})$/'; /** + * The VIN code + * * @var string */ private $vin; /** + * World manufacturer identifier + * * @var string */ private $wmi; /** + * Vehicle descriptor section + * * @var string */ private $vds; /** + * Vehicle identifier section + * * @var string */ private $vis; /** + * Vehicle region + * * @var null|string */ private $region; /** + * Vehicle country + * * @var null|string */ private $country; /** + * Vehicle manufacturer + * * @var null|string */ private $manufacturer; /** + * Vehicle model year + * * @var int[] */ private $modelYear; @@ -91,7 +107,7 @@ public function __construct(string $value) // The given VIN must be in upper case... $value = strtoupper($value); - if (! preg_match(self::REGEX, $value, $match)) { + if (!preg_match(self::REGEX, $value, $match)) { throw new InvalidArgumentException( sprintf('The value "%s" is not a valid VIN', $value) ); @@ -104,10 +120,10 @@ public function __construct(string $value) $this->vis = $match['vis']; // Parsed values - $this->region = $this->identifyRegion(); - $this->country = $this->identifyCountry(); - $this->manufacturer = $this->identifyManufacturer(); - $this->modelYear = $this->identifyModelYear(); + $this->region = $this->determineRegion(); + $this->country = $this->determineCountry(); + $this->manufacturer = $this->determineManufacturer(); + $this->modelYear = $this->determineModelYear(); } /** @@ -175,7 +191,9 @@ public function getModelYear() : array } /** - * {@inheritDoc} + * Converts the object to array + * + * @return array */ public function toArray() : array { @@ -192,31 +210,30 @@ public function toArray() : array } /** + * Tries to determine vehicle region + * * @return null|string */ - private function identifyRegion() : ?string + private function determineRegion() : ?string { - // undefined region... - if (! isset(REGIONS[$this->wmi[0]])) { - return null; - } - return REGIONS[$this->wmi[0]]['region'] ?? null; } /** + * Tries to determine vehicle country + * * @return null|string */ - private function identifyCountry() : ?string + private function determineCountry() : ?string { - // undefined region... - if (! isset(REGIONS[$this->wmi[0]])) { + $countries = REGIONS[$this->wmi[0]]['countries'] ?? null; + if (null === $countries) { return null; } - foreach (REGIONS[$this->wmi[0]]['countries'] as $chars => $title) { - if (! (false === strpbrk($this->wmi[1], (string) $chars))) { - return $title; + foreach ($countries as $chars => $name) { + if (!(false === strpbrk($this->wmi[1], (string) $chars))) { + return $name; } } @@ -224,24 +241,28 @@ private function identifyCountry() : ?string } /** + * Tries to determine vehicle manufacturer + * * @return null|string */ - private function identifyManufacturer() : ?string + private function determineManufacturer() : ?string { return MANUFACTURERS[$this->wmi] ?? MANUFACTURERS[$this->wmi[0] . $this->wmi[1]] ?? null; } /** + * Tries to determine vehicle model year(s) + * * @return int[] */ - private function identifyModelYear() : array + private function determineModelYear() : array { $comingYear = (int) date('Y') + 1; - $certainYears = []; + $estimatedYears = []; foreach (YEARS as $year => $char) { if ($this->vis[0] === $char) { - $certainYears[] = $year; + $estimatedYears[] = $year; } if ($comingYear === $year) { @@ -249,6 +270,6 @@ private function identifyModelYear() : array } } - return $certainYears; + return $estimatedYears; } } diff --git a/src/VinInterface.php b/src/VinInterface.php index 258a370..1a9eed2 100644 --- a/src/VinInterface.php +++ b/src/VinInterface.php @@ -96,11 +96,4 @@ public function getManufacturer() : ?string; * @since 1.0.13 */ public function getModelYear() : array; - - /** - * Converts the VIN to array - * - * @return array - */ - public function toArray() : array; }