From e91395cb4e4257ee66f15898312968fe5074e4fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Bourgoin?= Date: Fri, 1 Feb 2019 15:07:22 +0100 Subject: [PATCH 01/11] Fix README file name extension --- README => README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README => README.md (100%) diff --git a/README b/README.md similarity index 100% rename from README rename to README.md From 3534e62cbdd37e7c6f9283165c220e81f5846980 Mon Sep 17 00:00:00 2001 From: Clement Bourgoin Date: Wed, 6 Feb 2019 17:03:17 +0100 Subject: [PATCH 02/11] Fix considering ISBNs with an invalid country code as valid --- README.md | 4 ++++ src/Biblys/Isbn/Isbn.php | 9 ++++++++- tests/IsbnTest.php | 13 ++++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f036c43..8b861da 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,10 @@ following commands: ## Changelog +### DEV + +- Fixed considering ISBNs with an invalid country code as valid + ### 2.0.7 (2019-02-01) - Attempts to format an invalid ISBN will now throw an Exception diff --git a/src/Biblys/Isbn/Isbn.php b/src/Biblys/Isbn/Isbn.php index 4e5ba7f..4e726ca 100644 --- a/src/Biblys/Isbn/Isbn.php +++ b/src/Biblys/Isbn/Isbn.php @@ -19,7 +19,7 @@ class Isbn ERROR_INVALID_CHARACTERS = 'Invalid characters in the code', ERROR_INVALID_LENGTH = 'Code is too short or too long', ERROR_INVALID_PRODUCT_CODE = 'Product code should be 978 or 979', - ERROR_INVALID_COUNTRY = 'Country code unknown'; + ERROR_INVALID_COUNTRY_CODE = 'Country code is unknown'; private $_product, // GS1 Product Code (978 or 979 for books) $_country, // Registrant group (country) code @@ -252,6 +252,13 @@ private function removeCountryCode($code) } } + // Country code is invalid + if ($length === "0") { + $this->setValid(false); + $this->addError(self::ERROR_INVALID_COUNTRY_CODE); + return $code; + } + $this->setCountry(substr($code,0,$length)); $code = substr($code,$length); diff --git a/tests/IsbnTest.php b/tests/IsbnTest.php index 91ea94c..1eab009 100644 --- a/tests/IsbnTest.php +++ b/tests/IsbnTest.php @@ -79,9 +79,20 @@ public function testIsbn10WithChecksumX() * @expectedException Exception * @expectedExceptionMessage Cannot format invalid ISBN: [6897896354577] Product code should be 978 or 979 */ - public function testFormatingInvalidIsbn() + public function testIsbnWithInvalidProductCode() { $isbn = new Isbn('6897896354577'); + $this->assertFalse($isbn->isValid()); $isbn13 = $isbn->format('EAN'); } + + /** + * @expectedException Exception + * @expectedExceptionMessage Cannot format invalid ISBN: [9798887382562] Country code is unknown + */ + public function testIsbnWithInvalidCountryCode() { + $isbn = new Isbn('9798887382562'); + $this->assertFalse($isbn->isValid()); + $this->assertEquals($isbn->format('EAN'), '9798887382562'); + } } From 7255e48ace69ab89b67e9885b2bca949b39a4611 Mon Sep 17 00:00:00 2001 From: Clement Bourgoin Date: Wed, 6 Feb 2019 17:58:09 +0100 Subject: [PATCH 03/11] Add PHP versions 7.1 & 7.2 to travis config file --- .travis.yml | 2 ++ README.md | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9d828e6..7f60d95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,8 @@ language: php php: - '5.6' - '7.0' + - '7.1' + - '7.2' before_script: composer install diff --git a/README.md b/README.md index 8b861da..94322e1 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,9 @@ following commands: ### DEV -- Fixed considering ISBNs with an invalid country code as valid +- Fixed [#7] ISBNs with invalid product code or country code are considered + valid +- Added PHP versions 7.1 & 7.2 to travis config file ### 2.0.7 (2019-02-01) @@ -80,8 +82,8 @@ following commands: ### 2.0.6 (2017-11-22) -- Fixed [#6](https://github.com/biblys/isbn/issues/6): Error when validating ISBN-10 with - X as a checksum digit +- Fixed [#6](https://github.com/biblys/isbn/issues/6): Error when validating + ISBN-10 with X as a checksum digit ### 2.0.5 (2017-11-07) From 4f959cf4d94902d66caee8b933c2fa347449dc7b Mon Sep 17 00:00:00 2001 From: Clement Bourgoin Date: Thu, 7 Feb 2019 14:16:07 +0100 Subject: [PATCH 04/11] Bump version to 2.0.8 & update changelog --- README.md | 6 ++--- composer.json | 64 +++++++++++++++++++++++++++------------------------ 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 94322e1..42411b5 100644 --- a/README.md +++ b/README.md @@ -68,10 +68,10 @@ following commands: ## Changelog -### DEV +### 2.0.8 -- Fixed [#7] ISBNs with invalid product code or country code are considered - valid +- Fixed [#7](https://github.com/biblys/isbn/issues/7) ISBNs with invalid product + code or country code are considered valid - Added PHP versions 7.1 & 7.2 to travis config file ### 2.0.7 (2019-02-01) diff --git a/composer.json b/composer.json index c278254..c4e7f0f 100644 --- a/composer.json +++ b/composer.json @@ -1,33 +1,37 @@ { - "name": "biblys/isbn", - "description": "A PHP library to convert and validate ISBNs & EANs", - "time": "2019-02-01", - "keywords": ["ISBN", "EAN", "Book"], - "license": "MIT", - "homepage": "https://github.com/biblys/isbn", - "authors": [ - { - "name": "Clement Bourgoin", - "email": "cb@nokto.net" - } - ], - "support": { - "issues": "https://github.com/biblys/isbn/issues" - }, - "require": { - "php": ">=5.3.0" - }, - "require-dev": { - "phpunit/phpunit": "^5.2", - "guzzlehttp/guzzle": "^6.2" - }, - "autoload": { - "psr-0": { - "Biblys": "src/" - } - }, - "scripts": { - "test": "vendor/bin/phpunit tests", - "update-ranges": "php bin/update-ranges.php" + "name": "biblys/isbn", + "description": "A PHP library to convert and validate ISBNs & EANs", + "time": "2019-02-07", + "keywords": [ + "ISBN", + "EAN", + "Book" + ], + "license": "MIT", + "homepage": "https://github.com/biblys/isbn", + "authors": [ + { + "name": "Clement Bourgoin", + "email": "cb@nokto.net" } + ], + "support": { + "issues": "https://github.com/biblys/isbn/issues" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.2", + "guzzlehttp/guzzle": "^6.2" + }, + "autoload": { + "psr-0": { + "Biblys": "src/" + } + }, + "scripts": { + "test": "vendor/bin/phpunit tests", + "update-ranges": "php bin/update-ranges.php" + } } From 6fa3d304ec5953a40963d34c89fabfdb5bbdc629 Mon Sep 17 00:00:00 2001 From: Clement Bourgoin Date: Wed, 17 Apr 2019 09:13:48 +0200 Subject: [PATCH 05/11] Fix code formatting --- src/Biblys/Isbn/Isbn.php | 730 +++++++++++++++++++-------------------- 1 file changed, 358 insertions(+), 372 deletions(-) diff --git a/src/Biblys/Isbn/Isbn.php b/src/Biblys/Isbn/Isbn.php index 4e726ca..c07067f 100644 --- a/src/Biblys/Isbn/Isbn.php +++ b/src/Biblys/Isbn/Isbn.php @@ -14,391 +14,377 @@ class Isbn { - // Error messages (for localization) - const ERROR_EMPTY = 'No code provided', - ERROR_INVALID_CHARACTERS = 'Invalid characters in the code', - ERROR_INVALID_LENGTH = 'Code is too short or too long', - ERROR_INVALID_PRODUCT_CODE = 'Product code should be 978 or 979', - ERROR_INVALID_COUNTRY_CODE = 'Country code is unknown'; - - private $_product, // GS1 Product Code (978 or 979 for books) - $_country, // Registrant group (country) code - $_publisher, // Registrant (publisher) Code - $_publication, // Publication code - $_checksum, // Checksum character - $_input, // Input code - $_isValid = true, // Is the code a valid ISBN - $_errors = array(), // Why is the code invalid - $_format = 'EAN', // Output format - $_prefixes, // XML ranges file prefixes - $_groups, // XML ranges file groups - $_agency; // ISBN Agency - - /** - * @var Ranges - */ - private $ranges = NULL; - - public function __construct($code = NULL) - { - if (!empty($code)) - { - $this->_input = $code; - - // Remove hyphens and check characters - $code = $this->removeHyphens($code); - - // Remove checksum and check length - $code = $this->removeChecksum($code); - - if ($this->isValid()) - { - // Remove (and set) product code - $code = $this->removeProductCode($code); - - // Remove (and save) country code - $code = $this->removeCountryCode($code); - - // Remove (and save) publisher code - $this->removePublisherCode($code); - } - } - else - { - $this->addError(self::ERROR_EMPTY); - $this->setValid(false); - } - - } - - /** - * Gets a class that knows about the ISBN ranges - * - * @return Ranges - */ - public function getRanges() - { - if ($this->ranges !== NULL) { - return $this->ranges; - } - return $this->ranges = new Ranges(); - } - - /* Check methods */ - - /** - * Check if ISBN is valid - */ - public function isValid() - { - return (bool) $this->_isValid; - } - - /* Format methods */ - - /** - * Format an ISBN according to specified format - * @param string $format (ISBN-10, ISBN-13, EAN) - */ - public function format($format = 'EAN') - { - if (!$this->isValid()) { - throw new \Exception('Cannot format invalid ISBN: '.$this->getErrors()); - } - - $this->calculateChecksum($format); - - $A = $this->getProduct(); - $B = $this->getCountry(); - $C = $this->getPublisher(); - $D = $this->getPublication(); - $E = $this->getChecksum(); - - if($format == 'ISBN-10') - { - return $B.'-'.$C.'-'.$D.'-'.$E; - } - elseif($format == 'ISBN-13' || $format == 'ISBN') - { - return $A.'-'.$B.'-'.$C.'-'.$D.'-'.$E; - } - else - { - return $A.$B.$C.$D.$E; - } - } - - // Private methods - - /** - * Set ISBN Validity - */ - private function setValid($isValid) - { - $this->_isValid = (bool) $isValid; - } - - /** - * Add to error log - */ - private function addError($error) - { - $this->_errors[] = (string) $error; - } - - /** - * Delete '-', '_' and ' ' - */ - private function removeHyphens($code) - { - // Remove Hyphens and others characters - $replacements = array('-','_',' '); - $code = str_replace($replacements,'',$code); - - // Check for unwanted characters - if (!is_numeric($code) - && !(is_numeric(substr($code, 0, -1)) - && strtoupper(substr($code, -1)) == 'X')) { - $this->setValid(false); - $this->addError(self::ERROR_INVALID_CHARACTERS); - } - - return $code; - } - - /** - * Remove checksum character if present - */ - private function removeChecksum($code) - { - $length = strlen($code); - if ($length == 13 || $length == 10) - { - $code = substr_replace($code,"",-1); - return $code; - } - elseif ($length == 12 || $length == 9) - { - return $code; - } - else - { - $this->setValid(false); - $this->addError(self::ERROR_INVALID_LENGTH); - return $code; - } - } - - /** - * Remove first three characters if 978 or 979 and save Product Code - */ - private function removeProductCode($code) - { - - $first3 = substr($code,0,3); - - // For ISBN-10, product code is always 978 - if (strlen($code) == 9) { - $this->setProduct(978); - } - - // ISBN-13: check that product code is 978 or 979 - elseif ($first3 == 978 || $first3 == 979) { - $this->setProduct($first3); - $code = substr($code, 3); - } - - // Product code is Invalid - else { - $this->setValid(false); - $this->addError(self::ERROR_INVALID_PRODUCT_CODE); - } - - return $code; - } - - /** - * Remove and save Country Code - */ - private function removeCountryCode($code) - { - - // Get the seven first digits - $first7 = substr($code,0,7); - - // Select the right set of rules according to the product code - foreach ($this->getRanges()->getPrefixes() as $p) - { - if ($p['Prefix'] == $this->getProduct()) - { - $rules = $p['Rules']['Rule']; - break; - } - } - - // If product code was not found, cannot proceed - if (empty($rules)) { - return null; - } - - // Select the right rule - foreach ($rules as $r) - { - $ra = explode('-',$r['Range']); - if ($first7 >= $ra[0] && $first7 <= $ra[1]) - { - $length = $r['Length']; - break; - } - } - - // Country code is invalid - if ($length === "0") { - $this->setValid(false); - $this->addError(self::ERROR_INVALID_COUNTRY_CODE); - return $code; - } - - $this->setCountry(substr($code,0,$length)); - $code = substr($code,$length); - - return $code; - } - - /** - * Remove and save Publisher Code and Publication Code - */ - private function removePublisherCode($code) - { - - // Get the seven first digits - $first7 = substr($code,0,7); - - // Select the right set of rules according to the agency (product + country code) - foreach ($this->getRanges()->getGroups() as $g) - { - if ($g['Prefix'] <> $this->getProduct().'-'.$this->getCountry()) { - continue; + // Error messages (for localization) + const ERROR_EMPTY = 'No code provided', + ERROR_INVALID_CHARACTERS = 'Invalid characters in the code', + ERROR_INVALID_LENGTH = 'Code is too short or too long', + ERROR_INVALID_PRODUCT_CODE = 'Product code should be 978 or 979', + ERROR_INVALID_COUNTRY_CODE = 'Country code is unknown'; + + private $_product; + // GS1 Product Code (978 or 979 for books) + private $_country; + // Registrant group (country) code + private $_publisher; + // Registrant (publisher) Code + private $_publication; + // Publication code + private $_checksum; + // Checksum character + private $_input; + // Input code + private $_isValid = true; + // Is the code a valid ISBN + private $_errors = array(); + // Why is the code invalid + private $_format = 'EAN'; + // Output format + private $_prefixes; + // XML ranges file prefixes + private $_groups; + // XML ranges file groups + private $_agency; // ISBN Agency + + /** + * @var Ranges + */ + private $ranges = null; + + public function __construct($code = null) + { + if (!empty($code)) { + $this->_input = $code; + + // Remove hyphens and check characters + $code = $this->removeHyphens($code); + + // Remove checksum and check length + $code = $this->removeChecksum($code); + + if ($this->isValid()) { + // Remove (and set) product code + $code = $this->removeProductCode($code); + + // Remove (and save) country code + $code = $this->removeCountryCode($code); + + // Remove (and save) publisher code + $this->removePublisherCode($code); + } + } else { + $this->addError(self::ERROR_EMPTY); + $this->setValid(false); + } + } + + /** + * Gets a class that knows about the ISBN ranges + * + * @return Ranges + */ + public function getRanges() + { + if ($this->ranges !== null) { + return $this->ranges; + } + return $this->ranges = new Ranges(); + } + + /* Check methods */ + + /** + * Check if ISBN is valid + */ + public function isValid() + { + return (bool) $this->_isValid; + } + + /* Format methods */ + + /** + * Format an ISBN according to specified format + * @param string $format (ISBN-10, ISBN-13, EAN) + */ + public function format($format = 'EAN') + { + if (!$this->isValid()) { + throw new \Exception('Cannot format invalid ISBN: '.$this->getErrors()); + } + + $this->calculateChecksum($format); + + $A = $this->getProduct(); + $B = $this->getCountry(); + $C = $this->getPublisher(); + $D = $this->getPublication(); + $E = $this->getChecksum(); + + if ($format == 'ISBN-10') { + return $B.'-'.$C.'-'.$D.'-'.$E; + } elseif ($format == 'ISBN-13' || $format == 'ISBN') { + return $A.'-'.$B.'-'.$C.'-'.$D.'-'.$E; + } else { + return $A.$B.$C.$D.$E; + } + } + + // Private methods + + /** + * Set ISBN Validity + */ + private function setValid($isValid) + { + $this->_isValid = (bool) $isValid; + } + + /** + * Add to error log + */ + private function addError($error) + { + $this->_errors[] = (string) $error; + } + + /** + * Delete '-', '_' and ' ' + */ + private function removeHyphens($code) + { + // Remove Hyphens and others characters + $replacements = array('-','_',' '); + $code = str_replace($replacements, '', $code); + + // Check for unwanted characters + if (!is_numeric($code) + && !(is_numeric(substr($code, 0, -1)) + && strtoupper(substr($code, -1)) == 'X')) { + $this->setValid(false); + $this->addError(self::ERROR_INVALID_CHARACTERS); + } + + return $code; + } + + /** + * Remove checksum character if present + */ + private function removeChecksum($code) + { + $length = strlen($code); + if ($length == 13 || $length == 10) { + $code = substr_replace($code, "", -1); + return $code; + } elseif ($length == 12 || $length == 9) { + return $code; + } else { + $this->setValid(false); + $this->addError(self::ERROR_INVALID_LENGTH); + return $code; + } + } + + /** + * Remove first three characters if 978 or 979 and save Product Code + */ + private function removeProductCode($code) + { + $first3 = substr($code, 0, 3); + + // For ISBN-10, product code is always 978 + if (strlen($code) == 9) { + $this->setProduct(978); + } + + // ISBN-13: check that product code is 978 or 979 + elseif ($first3 == 978 || $first3 == 979) { + $this->setProduct($first3); + $code = substr($code, 3); + } + + // Product code is Invalid + else { + $this->setValid(false); + $this->addError(self::ERROR_INVALID_PRODUCT_CODE); + } + + return $code; + } + + /** + * Remove and save Country Code + */ + private function removeCountryCode($code) + { + + // Get the seven first digits + $first7 = substr($code, 0, 7); + + // Select the right set of rules according to the product code + foreach ($this->getRanges()->getPrefixes() as $p) { + if ($p['Prefix'] == $this->getProduct()) { + $rules = $p['Rules']['Rule']; + break; + } + } + + // If product code was not found, cannot proceed + if (empty($rules)) { + return null; + } + + // Select the right rule + foreach ($rules as $r) { + $ra = explode('-', $r['Range']); + if ($first7 >= $ra[0] && $first7 <= $ra[1]) { + $length = $r['Length']; + break; + } + } + + // Country code is invalid + if ($length === "0") { + $this->setValid(false); + $this->addError(self::ERROR_INVALID_COUNTRY_CODE); + return $code; + } + + $this->setCountry(substr($code, 0, $length)); + $code = substr($code, $length); + + return $code; + } + + /** + * Remove and save Publisher Code and Publication Code + */ + private function removePublisherCode($code) + { + + // Get the seven first digits + $first7 = substr($code, 0, 7); + + // Select the right set of rules according to the agency (product + country code) + foreach ($this->getRanges()->getGroups() as $g) { + if ($g['Prefix'] <> $this->getProduct().'-'.$this->getCountry()) { + continue; } $rules = $g['Rules']['Rule']; $this->setAgency($g['Agency']); // Select the right rule - foreach ($rules as $r) - { - $ra = explode('-',$r['Range']); + foreach ($rules as $r) { + $ra = explode('-', $r['Range']); if ($first7 < $ra[0] || $first7 > $ra[1]) { continue; } $length = $r['Length']; - $this->setPublisher(substr($code,0,$length)); - $this->setPublication(substr($code,$length)); + $this->setPublisher(substr($code, 0, $length)); + $this->setPublication(substr($code, $length)); break; } break; } - } - - /** - * Calculate checksum character - */ - private function calculateChecksum($format = 'EAN') - { - $sum = null; - - if ($format == 'ISBN-10') - { - $code = $this->getCountry().$this->getPublisher().$this->getPublication(); - $c = str_split($code); - $sum = (11 - (($c[0] * 10) + ($c[1] * 9) + ($c[2] * 8) + ($c[3] * 7) + ($c[4] * 6) + ($c[5] * 5) + ($c[6] * 4) + ($c[7] * 3) + ($c[8] * 2)) % 11) % 11; - if($sum == 10) $sum = 'X'; - } - else - { - $code = $this->getProduct().$this->getCountry().$this->getPublisher().$this->getPublication(); - $c = str_split($code); - $sum = (($c[1] + $c[3] + $c[5] + $c[7] + $c[9] + $c[11]) * 3) + ($c[0] + $c[2] + $c[4] + $c[6] + $c[8] + $c[10]); - $sum = (10 - ($sum % 10)) % 10; - } - - $this->setChecksum($sum); - - } - - - /* SETTERS */ - - private function setProduct($product) - { - $this->_product = $product; - } - - private function setCountry($country) - { - $this->_country = $country; - } - - private function setPublisher($publisher) - { - $this->_publisher = $publisher; - } - - private function setPublication($publication) - { - $this->_publication = $publication; - } - - private function setChecksum($checksum) - { - $this->_checksum = $checksum; - } - - private function setAgency($agency) - { - $this->_agency = $agency; - } - - /* GETTERS */ - - public function getProduct() - { - return $this->_product; - } - - public function getCountry() - { - return $this->_country; - } - - public function getPublisher() - { - return $this->_publisher; - } - - public function getPublication() - { - return $this->_publication; - } - - public function getChecksum() - { - return $this->_checksum; - } - - public function getAgency() - { - return $this->_agency; - } - - public function getErrors() - { - $errors = '['.$this->_input.']'; - foreach ($this->_errors as $e) - { - $errors .= ' '.$e; - } - return $errors; - } + } + + /** + * Calculate checksum character + */ + private function calculateChecksum($format = 'EAN') + { + $sum = null; + + if ($format == 'ISBN-10') { + $code = $this->getCountry().$this->getPublisher().$this->getPublication(); + $c = str_split($code); + $sum = (11 - (($c[0] * 10) + ($c[1] * 9) + ($c[2] * 8) + ($c[3] * 7) + ($c[4] * 6) + ($c[5] * 5) + ($c[6] * 4) + ($c[7] * 3) + ($c[8] * 2)) % 11) % 11; + if ($sum == 10) { + $sum = 'X'; + } + } else { + $code = $this->getProduct().$this->getCountry().$this->getPublisher().$this->getPublication(); + $c = str_split($code); + $sum = (($c[1] + $c[3] + $c[5] + $c[7] + $c[9] + $c[11]) * 3) + ($c[0] + $c[2] + $c[4] + $c[6] + $c[8] + $c[10]); + $sum = (10 - ($sum % 10)) % 10; + } + + $this->setChecksum($sum); + } + + + /* SETTERS */ + + private function setProduct($product) + { + $this->_product = $product; + } + + private function setCountry($country) + { + $this->_country = $country; + } + + private function setPublisher($publisher) + { + $this->_publisher = $publisher; + } + + private function setPublication($publication) + { + $this->_publication = $publication; + } + + private function setChecksum($checksum) + { + $this->_checksum = $checksum; + } + + private function setAgency($agency) + { + $this->_agency = $agency; + } + + /* GETTERS */ + + public function getProduct() + { + return $this->_product; + } + + public function getCountry() + { + return $this->_country; + } + + public function getPublisher() + { + return $this->_publisher; + } + + public function getPublication() + { + return $this->_publication; + } + + public function getChecksum() + { + return $this->_checksum; + } + + public function getAgency() + { + return $this->_agency; + } + + public function getErrors() + { + $errors = '['.$this->_input.']'; + foreach ($this->_errors as $e) { + $errors .= ' '.$e; + } + return $errors; + } } From 8bca7b54d44649c9251bbe08d2c5d7c8b3221bd7 Mon Sep 17 00:00:00 2001 From: Clement Bourgoin Date: Wed, 17 Apr 2019 12:45:19 +0200 Subject: [PATCH 06/11] Add a validate method that throws an Exception --- src/Biblys/Isbn/Isbn.php | 10 ++++++++++ tests/IsbnTest.php | 24 +++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Biblys/Isbn/Isbn.php b/src/Biblys/Isbn/Isbn.php index c07067f..b48b066 100644 --- a/src/Biblys/Isbn/Isbn.php +++ b/src/Biblys/Isbn/Isbn.php @@ -387,4 +387,14 @@ public function getErrors() } return $errors; } + + public function validate() + { + $errors = $this->_errors; + if ($errors) { + throw new \Exception($errors[0]); + } + + return true; + } } diff --git a/tests/IsbnTest.php b/tests/IsbnTest.php index 1eab009..d4020ff 100644 --- a/tests/IsbnTest.php +++ b/tests/IsbnTest.php @@ -90,9 +90,31 @@ public function testIsbnWithInvalidProductCode() * @expectedException Exception * @expectedExceptionMessage Cannot format invalid ISBN: [9798887382562] Country code is unknown */ - public function testIsbnWithInvalidCountryCode() { + public function testIsbnWithInvalidCountryCode() + { $isbn = new Isbn('9798887382562'); $this->assertFalse($isbn->isValid()); $this->assertEquals($isbn->format('EAN'), '9798887382562'); } + + /** + * Validate method should return true for a valid ISBN + */ + public function testValidateValidIsbn() + { + $isbn = new Isbn('9782843449499'); + $this->assertTrue($isbn->validate()); + } + + /** + * Validate method should throw of an invalid ISBN + * + * @expectedException Exception + * @expectedExceptionMessage Product code should be 978 or 979 + */ + public function testValidateInvalidIsbn() + { + $isbn = new Isbn('6752843449499'); + $isbn->validate(); + } } From 5d4cacad4a1c55d081171bc335ef9d5a761bf78b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Bourgoin?= Date: Wed, 17 Apr 2019 13:29:43 +0200 Subject: [PATCH 07/11] Add a composer script to run tests in a Docker container --- README.md | 4 ++++ composer.json | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 42411b5..f3190d4 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,10 @@ Run tests with PHPUnit: $ composer install $ composer test +Run tests in a docker container: + + $ composer docker + ## ISBN ranges update New ISBN ranges may be added from time to time by the diff --git a/composer.json b/composer.json index c4e7f0f..07809dc 100644 --- a/composer.json +++ b/composer.json @@ -32,6 +32,7 @@ }, "scripts": { "test": "vendor/bin/phpunit tests", - "update-ranges": "php bin/update-ranges.php" + "update-ranges": "php bin/update-ranges.php", + "docker": "docker run --rm --volume $PWD:/app --volume $COMPOSER_HOME:/tmp composer /bin/bash -c \"composer install && composer test\"" } } From 55064323848045b86661f301a92f7453d1c77fda Mon Sep 17 00:00:00 2001 From: Clement Bourgoin Date: Wed, 17 Apr 2019 13:48:48 +0200 Subject: [PATCH 08/11] Add a validate method example in README --- README.md | 54 ++++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index f3190d4..590ff5d 100644 --- a/README.md +++ b/README.md @@ -13,37 +13,29 @@ This package can be used to : Install with composer: - $ composer require biblys/isbn:~2.0 +```console +composer require biblys/isbn:~2.0 +``` ## Usage +Use case: converting an EAN (9782843449499) to an ISBN-13 (978-2-84344-949-9). + ```php isValid()) { - - // Print the code in ISBN-13 format - echo $isbn->format('ISBN-13'); - - // Print the code in ISBN-10 format - echo $isbn->format('ISBN-10'); +$isbn = new Isbn('9782843449499'); - // Print the checksum digit - echo $isbn->getChecksum(); +$isbn = new Isbn($ean); - // Print the registration agency - echo $isbn->getAgency(); - -} else { - - // Show validation errors - echo $isbn->getErrors(); +try { + $isbn->validate(); + $isbn13 = $isbn->format("ISBN-13"); + echo "ISBN-13: $isbn13"; +} catch(Exception $e) { + echo "An error occured while parsing $ean: ".$e->getMessage(); } ``` @@ -51,12 +43,16 @@ if ($isbn->isValid()) { Run tests with PHPUnit: - $ composer install - $ composer test +```console +composer install +composer test +``` Run tests in a docker container: - $ composer docker +```console +composer docker +``` ## ISBN ranges update @@ -67,14 +63,16 @@ open an issue on Github. You can also open a pull request after updating the ranges your self with the following commands: - $ composer install - $ composer run update-ranges +```console +composer install +composer run update-ranges +``` ## Changelog -### 2.0.8 +### 2.0.8 (2019-02-07) -- Fixed [#7](https://github.com/biblys/isbn/issues/7) ISBNs with invalid product +- Fixed [#7](https://github.com/biblys/isbn/issues/7): ISBNs with invalid product code or country code are considered valid - Added PHP versions 7.1 & 7.2 to travis config file From 3925d8761d778a97dc06fae9b9d8ab94f7758df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Bourgoin?= Date: Wed, 17 Apr 2019 13:51:56 +0200 Subject: [PATCH 09/11] Add a composer script to run update-range in a Docker container --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 07809dc..f3f9bfd 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ "scripts": { "test": "vendor/bin/phpunit tests", "update-ranges": "php bin/update-ranges.php", - "docker": "docker run --rm --volume $PWD:/app --volume $COMPOSER_HOME:/tmp composer /bin/bash -c \"composer install && composer test\"" + "docker:test": "docker run --rm --volume $PWD:/app --volume $COMPOSER_HOME:/tmp composer /bin/bash -c \"composer install && composer test\"", + "docker:update-ranges": "docker run --rm --volume $PWD:/app --volume $COMPOSER_HOME:/tmp composer /bin/bash -c \"composer install && composer update-ranges\"" } } From 491964cacda2942ab8536ddcefd32eb1b2829858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Bourgoin?= Date: Wed, 17 Apr 2019 13:53:17 +0200 Subject: [PATCH 10/11] Update ISBN ranges --- src/Biblys/Isbn/ranges-array.php | 460 +++++++++++++++++++------------ 1 file changed, 286 insertions(+), 174 deletions(-) diff --git a/src/Biblys/Isbn/ranges-array.php b/src/Biblys/Isbn/ranges-array.php index 343f5fc..084fe3e 100644 --- a/src/Biblys/Isbn/ranges-array.php +++ b/src/Biblys/Isbn/ranges-array.php @@ -53,12 +53,12 @@ ), 6 => array ( - 'Range' => '6390000-6398999', + 'Range' => '6390000-6397999', 'Length' => '4', ), 7 => array ( - 'Range' => '6399000-6399999', + 'Range' => '6398000-6399999', 'Length' => '7', ), 8 => @@ -124,12 +124,12 @@ ), 1 => array ( - 'Range' => '0100000-0899999', + 'Range' => '0100000-0699999', 'Length' => '2', ), 2 => array ( - 'Range' => '0900000-0999999', + 'Range' => '0700000-0999999', 'Length' => '4', ), 3 => @@ -1483,37 +1483,47 @@ array ( 0 => array ( - 'Range' => '0000000-4999999', + 'Range' => '0000000-2999999', 'Length' => '0', ), 1 => array ( - 'Range' => '5000000-5004999', - 'Length' => '4', + 'Range' => '3000000-3029999', + 'Length' => '3', ), 2 => array ( - 'Range' => '5005000-7999999', + 'Range' => '3030000-4999999', 'Length' => '0', ), 3 => array ( - 'Range' => '8000000-8019999', - 'Length' => '5', + 'Range' => '5000000-5019999', + 'Length' => '4', ), 4 => array ( - 'Range' => '8020000-8999999', + 'Range' => '5020000-7999999', 'Length' => '0', ), 5 => array ( - 'Range' => '9000000-9003499', - 'Length' => '6', + 'Range' => '8000000-8069999', + 'Length' => '5', ), 6 => array ( - 'Range' => '9003500-9999999', + 'Range' => '8070000-8999999', + 'Length' => '0', + ), + 7 => + array ( + 'Range' => '9000000-9007999', + 'Length' => '6', + ), + 8 => + array ( + 'Range' => '9008000-9999999', 'Length' => '0', ), ), @@ -4061,12 +4071,12 @@ ), 1 => array ( - 'Range' => '1200000-5599999', + 'Range' => '1200000-5399999', 'Length' => '3', ), 2 => array ( - 'Range' => '5600000-7999999', + 'Range' => '5400000-7999999', 'Length' => '4', ), 3 => @@ -4256,6 +4266,93 @@ ), ), 87 => + array ( + 'Prefix' => '978-9918', + 'Agency' => 'Malta', + 'Rules' => + array ( + 'Rule' => + array ( + 0 => + array ( + 'Range' => '0000000-0999999', + 'Length' => '1', + ), + 1 => + array ( + 'Range' => '1000000-1999999', + 'Length' => '0', + ), + 2 => + array ( + 'Range' => '2000000-2999999', + 'Length' => '2', + ), + 3 => + array ( + 'Range' => '3000000-5999999', + 'Length' => '0', + ), + 4 => + array ( + 'Range' => '6000000-7999999', + 'Length' => '3', + ), + 5 => + array ( + 'Range' => '8000000-9499999', + 'Length' => '0', + ), + 6 => + array ( + 'Range' => '9500000-9999999', + 'Length' => '4', + ), + ), + ), + ), + 88 => + array ( + 'Prefix' => '978-9919', + 'Agency' => 'Mongolia', + 'Rules' => + array ( + 'Rule' => + array ( + 0 => + array ( + 'Range' => '0000000-1999999', + 'Length' => '0', + ), + 1 => + array ( + 'Range' => '2000000-2799999', + 'Length' => '2', + ), + 2 => + array ( + 'Range' => '2800000-4999999', + 'Length' => '0', + ), + 3 => + array ( + 'Range' => '5000000-5999999', + 'Length' => '3', + ), + 4 => + array ( + 'Range' => '6000000-9499999', + 'Length' => '0', + ), + 5 => + array ( + 'Range' => '9500000-9999999', + 'Length' => '4', + ), + ), + ), + ), + 89 => array ( 'Prefix' => '978-9920', 'Agency' => 'Morocco', @@ -4275,12 +4372,12 @@ ), 2 => array ( - 'Range' => '4000000-6999999', + 'Range' => '4000000-6749999', 'Length' => '0', ), 3 => array ( - 'Range' => '7000000-7999999', + 'Range' => '6750000-7999999', 'Length' => '3', ), 4 => @@ -4296,7 +4393,7 @@ ), ), ), - 88 => + 90 => array ( 'Prefix' => '978-9921', 'Agency' => 'Kuwait', @@ -4342,7 +4439,7 @@ ), ), ), - 89 => + 91 => array ( 'Prefix' => '978-9922', 'Agency' => 'Iraq', @@ -4383,7 +4480,7 @@ ), ), ), - 90 => + 92 => array ( 'Prefix' => '978-9923', 'Agency' => 'Jordan', @@ -4424,7 +4521,7 @@ ), ), ), - 91 => + 93 => array ( 'Prefix' => '978-9924', 'Agency' => 'Cambodia', @@ -4465,7 +4562,7 @@ ), ), ), - 92 => + 94 => array ( 'Prefix' => '978-9925', 'Agency' => 'Cyprus', @@ -4496,7 +4593,7 @@ ), ), ), - 93 => + 95 => array ( 'Prefix' => '978-9926', 'Agency' => 'Bosnia and Herzegovina', @@ -4527,7 +4624,7 @@ ), ), ), - 94 => + 96 => array ( 'Prefix' => '978-9927', 'Agency' => 'Qatar', @@ -4558,7 +4655,7 @@ ), ), ), - 95 => + 97 => array ( 'Prefix' => '978-9928', 'Agency' => 'Albania', @@ -4589,7 +4686,7 @@ ), ), ), - 96 => + 98 => array ( 'Prefix' => '978-9929', 'Agency' => 'Guatemala', @@ -4620,7 +4717,7 @@ ), ), ), - 97 => + 99 => array ( 'Prefix' => '978-9930', 'Agency' => 'Costa Rica', @@ -4646,7 +4743,7 @@ ), ), ), - 98 => + 100 => array ( 'Prefix' => '978-9931', 'Agency' => 'Algeria', @@ -4672,7 +4769,7 @@ ), ), ), - 99 => + 101 => array ( 'Prefix' => '978-9932', 'Agency' => 'Lao People\'s Democratic Republic', @@ -4698,7 +4795,7 @@ ), ), ), - 100 => + 102 => array ( 'Prefix' => '978-9933', 'Agency' => 'Syria', @@ -4729,7 +4826,7 @@ ), ), ), - 101 => + 103 => array ( 'Prefix' => '978-9934', 'Agency' => 'Latvia', @@ -4760,7 +4857,7 @@ ), ), ), - 102 => + 104 => array ( 'Prefix' => '978-9935', 'Agency' => 'Iceland', @@ -4791,7 +4888,7 @@ ), ), ), - 103 => + 105 => array ( 'Prefix' => '978-9936', 'Agency' => 'Afghanistan', @@ -4822,7 +4919,7 @@ ), ), ), - 104 => + 106 => array ( 'Prefix' => '978-9937', 'Agency' => 'Nepal', @@ -4853,7 +4950,7 @@ ), ), ), - 105 => + 107 => array ( 'Prefix' => '978-9938', 'Agency' => 'Tunisia', @@ -4879,7 +4976,7 @@ ), ), ), - 106 => + 108 => array ( 'Prefix' => '978-9939', 'Agency' => 'Armenia', @@ -4904,13 +5001,18 @@ ), 3 => array ( - 'Range' => '9000000-9999999', + 'Range' => '9000000-9799999', 'Length' => '4', ), + 4 => + array ( + 'Range' => '9800000-9999999', + 'Length' => '2', + ), ), ), ), - 107 => + 109 => array ( 'Prefix' => '978-9940', 'Agency' => 'Montenegro', @@ -4941,7 +5043,7 @@ ), ), ), - 108 => + 110 => array ( 'Prefix' => '978-9941', 'Agency' => 'Georgia', @@ -4977,7 +5079,7 @@ ), ), ), - 109 => + 111 => array ( 'Prefix' => '978-9942', 'Agency' => 'Ecuador', @@ -5013,7 +5115,7 @@ ), ), ), - 110 => + 112 => array ( 'Prefix' => '978-9943', 'Agency' => 'Uzbekistan', @@ -5044,7 +5146,7 @@ ), ), ), - 111 => + 113 => array ( 'Prefix' => '978-9944', 'Agency' => 'Turkey', @@ -5090,7 +5192,7 @@ ), ), ), - 112 => + 114 => array ( 'Prefix' => '978-9945', 'Agency' => 'Dominican Republic', @@ -5136,7 +5238,7 @@ ), ), ), - 113 => + 115 => array ( 'Prefix' => '978-9946', 'Agency' => 'Korea, P.D.R.', @@ -5167,7 +5269,7 @@ ), ), ), - 114 => + 116 => array ( 'Prefix' => '978-9947', 'Agency' => 'Algeria', @@ -5193,7 +5295,7 @@ ), ), ), - 115 => + 117 => array ( 'Prefix' => '978-9948', 'Agency' => 'United Arab Emirates', @@ -5219,7 +5321,7 @@ ), ), ), - 116 => + 118 => array ( 'Prefix' => '978-9949', 'Agency' => 'Estonia', @@ -5270,7 +5372,7 @@ ), ), ), - 117 => + 119 => array ( 'Prefix' => '978-9950', 'Agency' => 'Palestine', @@ -5296,7 +5398,7 @@ ), ), ), - 118 => + 120 => array ( 'Prefix' => '978-9951', 'Agency' => 'Kosova', @@ -5322,7 +5424,7 @@ ), ), ), - 119 => + 121 => array ( 'Prefix' => '978-9952', 'Agency' => 'Azerbaijan', @@ -5353,7 +5455,7 @@ ), ), ), - 120 => + 122 => array ( 'Prefix' => '978-9953', 'Agency' => 'Lebanon', @@ -5399,7 +5501,7 @@ ), ), ), - 121 => + 123 => array ( 'Prefix' => '978-9954', 'Agency' => 'Morocco', @@ -5435,7 +5537,7 @@ ), ), ), - 122 => + 124 => array ( 'Prefix' => '978-9955', 'Agency' => 'Lithuania', @@ -5461,7 +5563,7 @@ ), ), ), - 123 => + 125 => array ( 'Prefix' => '978-9956', 'Agency' => 'Cameroon', @@ -5492,7 +5594,7 @@ ), ), ), - 124 => + 126 => array ( 'Prefix' => '978-9957', 'Agency' => 'Jordan', @@ -5538,7 +5640,7 @@ ), ), ), - 125 => + 127 => array ( 'Prefix' => '978-9958', 'Agency' => 'Bosnia and Herzegovina', @@ -5599,7 +5701,7 @@ ), ), ), - 126 => + 128 => array ( 'Prefix' => '978-9959', 'Agency' => 'Libya', @@ -5640,7 +5742,7 @@ ), ), ), - 127 => + 129 => array ( 'Prefix' => '978-9960', 'Agency' => 'Saudi Arabia', @@ -5666,7 +5768,7 @@ ), ), ), - 128 => + 130 => array ( 'Prefix' => '978-9961', 'Agency' => 'Algeria', @@ -5697,7 +5799,7 @@ ), ), ), - 129 => + 131 => array ( 'Prefix' => '978-9962', 'Agency' => 'Panama', @@ -5733,7 +5835,7 @@ ), ), ), - 130 => + 132 => array ( 'Prefix' => '978-9963', 'Agency' => 'Cyprus', @@ -5784,7 +5886,7 @@ ), ), ), - 131 => + 133 => array ( 'Prefix' => '978-9964', 'Agency' => 'Ghana', @@ -5810,7 +5912,7 @@ ), ), ), - 132 => + 134 => array ( 'Prefix' => '978-9965', 'Agency' => 'Kazakhstan', @@ -5836,7 +5938,7 @@ ), ), ), - 133 => + 135 => array ( 'Prefix' => '978-9966', 'Agency' => 'Kenya', @@ -5892,7 +5994,7 @@ ), ), ), - 134 => + 136 => array ( 'Prefix' => '978-9967', 'Agency' => 'Kyrgyz Republic', @@ -5918,7 +6020,7 @@ ), ), ), - 135 => + 137 => array ( 'Prefix' => '978-9968', 'Agency' => 'Costa Rica', @@ -5944,7 +6046,7 @@ ), ), ), - 136 => + 138 => array ( 'Prefix' => '978-9970', 'Agency' => 'Uganda', @@ -5970,7 +6072,7 @@ ), ), ), - 137 => + 139 => array ( 'Prefix' => '978-9971', 'Agency' => 'Singapore', @@ -6001,7 +6103,7 @@ ), ), ), - 138 => + 140 => array ( 'Prefix' => '978-9972', 'Agency' => 'Peru', @@ -6047,7 +6149,7 @@ ), ), ), - 139 => + 141 => array ( 'Prefix' => '978-9973', 'Agency' => 'Tunisia', @@ -6088,7 +6190,7 @@ ), ), ), - 140 => + 142 => array ( 'Prefix' => '978-9974', 'Agency' => 'Uruguay', @@ -6134,7 +6236,7 @@ ), ), ), - 141 => + 143 => array ( 'Prefix' => '978-9975', 'Agency' => 'Moldova', @@ -6180,7 +6282,7 @@ ), ), ), - 142 => + 144 => array ( 'Prefix' => '978-9976', 'Agency' => 'Tanzania', @@ -6216,7 +6318,7 @@ ), ), ), - 143 => + 145 => array ( 'Prefix' => '978-9977', 'Agency' => 'Costa Rica', @@ -6242,7 +6344,7 @@ ), ), ), - 144 => + 146 => array ( 'Prefix' => '978-9978', 'Agency' => 'Ecuador', @@ -6278,7 +6380,7 @@ ), ), ), - 145 => + 147 => array ( 'Prefix' => '978-9979', 'Agency' => 'Iceland', @@ -6319,7 +6421,7 @@ ), ), ), - 146 => + 148 => array ( 'Prefix' => '978-9980', 'Agency' => 'Papua New Guinea', @@ -6350,7 +6452,7 @@ ), ), ), - 147 => + 149 => array ( 'Prefix' => '978-9981', 'Agency' => 'Morocco', @@ -6391,7 +6493,7 @@ ), ), ), - 148 => + 150 => array ( 'Prefix' => '978-9982', 'Agency' => 'Zambia', @@ -6417,7 +6519,7 @@ ), ), ), - 149 => + 151 => array ( 'Prefix' => '978-9983', 'Agency' => 'Gambia', @@ -6448,7 +6550,7 @@ ), ), ), - 150 => + 152 => array ( 'Prefix' => '978-9984', 'Agency' => 'Latvia', @@ -6474,7 +6576,7 @@ ), ), ), - 151 => + 153 => array ( 'Prefix' => '978-9985', 'Agency' => 'Estonia', @@ -6505,7 +6607,7 @@ ), ), ), - 152 => + 154 => array ( 'Prefix' => '978-9986', 'Agency' => 'Lithuania', @@ -6541,7 +6643,7 @@ ), ), ), - 153 => + 155 => array ( 'Prefix' => '978-9987', 'Agency' => 'Tanzania', @@ -6567,7 +6669,7 @@ ), ), ), - 154 => + 156 => array ( 'Prefix' => '978-9988', 'Agency' => 'Ghana', @@ -6598,7 +6700,7 @@ ), ), ), - 155 => + 157 => array ( 'Prefix' => '978-9989', 'Agency' => 'Macedonia', @@ -6639,7 +6741,7 @@ ), ), ), - 156 => + 158 => array ( 'Prefix' => '978-99901', 'Agency' => 'Bahrain', @@ -6665,7 +6767,7 @@ ), ), ), - 157 => + 159 => array ( 'Prefix' => '978-99902', 'Agency' => 'Reserved Agency', @@ -6681,7 +6783,7 @@ ), ), ), - 158 => + 160 => array ( 'Prefix' => '978-99903', 'Agency' => 'Mauritius', @@ -6707,7 +6809,7 @@ ), ), ), - 159 => + 161 => array ( 'Prefix' => '978-99904', 'Agency' => 'CuraƧao', @@ -6733,7 +6835,7 @@ ), ), ), - 160 => + 162 => array ( 'Prefix' => '978-99905', 'Agency' => 'Bolivia', @@ -6759,7 +6861,7 @@ ), ), ), - 161 => + 163 => array ( 'Prefix' => '978-99906', 'Agency' => 'Kuwait', @@ -6800,7 +6902,7 @@ ), ), ), - 162 => + 164 => array ( 'Prefix' => '978-99908', 'Agency' => 'Malawi', @@ -6826,7 +6928,7 @@ ), ), ), - 163 => + 165 => array ( 'Prefix' => '978-99909', 'Agency' => 'Malta', @@ -6852,7 +6954,7 @@ ), ), ), - 164 => + 166 => array ( 'Prefix' => '978-99910', 'Agency' => 'Sierra Leone', @@ -6878,7 +6980,7 @@ ), ), ), - 165 => + 167 => array ( 'Prefix' => '978-99911', 'Agency' => 'Lesotho', @@ -6899,7 +7001,7 @@ ), ), ), - 166 => + 168 => array ( 'Prefix' => '978-99912', 'Agency' => 'Botswana', @@ -6930,7 +7032,7 @@ ), ), ), - 167 => + 169 => array ( 'Prefix' => '978-99913', 'Agency' => 'Andorra', @@ -6966,7 +7068,7 @@ ), ), ), - 168 => + 170 => array ( 'Prefix' => '978-99914', 'Agency' => 'International NGO Publishers', @@ -7002,7 +7104,7 @@ ), ), ), - 169 => + 171 => array ( 'Prefix' => '978-99915', 'Agency' => 'Maldives', @@ -7028,7 +7130,7 @@ ), ), ), - 170 => + 172 => array ( 'Prefix' => '978-99916', 'Agency' => 'Namibia', @@ -7054,7 +7156,7 @@ ), ), ), - 171 => + 173 => array ( 'Prefix' => '978-99917', 'Agency' => 'Brunei Darussalam', @@ -7080,7 +7182,7 @@ ), ), ), - 172 => + 174 => array ( 'Prefix' => '978-99918', 'Agency' => 'Faroe Islands', @@ -7106,7 +7208,7 @@ ), ), ), - 173 => + 175 => array ( 'Prefix' => '978-99919', 'Agency' => 'Benin', @@ -7137,7 +7239,7 @@ ), ), ), - 174 => + 176 => array ( 'Prefix' => '978-99920', 'Agency' => 'Andorra', @@ -7163,7 +7265,7 @@ ), ), ), - 175 => + 177 => array ( 'Prefix' => '978-99921', 'Agency' => 'Qatar', @@ -7199,7 +7301,7 @@ ), ), ), - 176 => + 178 => array ( 'Prefix' => '978-99922', 'Agency' => 'Guatemala', @@ -7225,7 +7327,7 @@ ), ), ), - 177 => + 179 => array ( 'Prefix' => '978-99923', 'Agency' => 'El Salvador', @@ -7251,7 +7353,7 @@ ), ), ), - 178 => + 180 => array ( 'Prefix' => '978-99924', 'Agency' => 'Nicaragua', @@ -7277,7 +7379,7 @@ ), ), ), - 179 => + 181 => array ( 'Prefix' => '978-99925', 'Agency' => 'Paraguay', @@ -7303,7 +7405,7 @@ ), ), ), - 180 => + 182 => array ( 'Prefix' => '978-99926', 'Agency' => 'Honduras', @@ -7339,7 +7441,7 @@ ), ), ), - 181 => + 183 => array ( 'Prefix' => '978-99927', 'Agency' => 'Albania', @@ -7365,7 +7467,7 @@ ), ), ), - 182 => + 184 => array ( 'Prefix' => '978-99928', 'Agency' => 'Georgia', @@ -7391,7 +7493,7 @@ ), ), ), - 183 => + 185 => array ( 'Prefix' => '978-99929', 'Agency' => 'Mongolia', @@ -7417,7 +7519,7 @@ ), ), ), - 184 => + 186 => array ( 'Prefix' => '978-99930', 'Agency' => 'Armenia', @@ -7443,7 +7545,7 @@ ), ), ), - 185 => + 187 => array ( 'Prefix' => '978-99931', 'Agency' => 'Seychelles', @@ -7469,7 +7571,7 @@ ), ), ), - 186 => + 188 => array ( 'Prefix' => '978-99932', 'Agency' => 'Malta', @@ -7505,7 +7607,7 @@ ), ), ), - 187 => + 189 => array ( 'Prefix' => '978-99933', 'Agency' => 'Nepal', @@ -7531,7 +7633,7 @@ ), ), ), - 188 => + 190 => array ( 'Prefix' => '978-99934', 'Agency' => 'Dominican Republic', @@ -7557,7 +7659,7 @@ ), ), ), - 189 => + 191 => array ( 'Prefix' => '978-99935', 'Agency' => 'Haiti', @@ -7593,7 +7695,7 @@ ), ), ), - 190 => + 192 => array ( 'Prefix' => '978-99936', 'Agency' => 'Bhutan', @@ -7619,7 +7721,7 @@ ), ), ), - 191 => + 193 => array ( 'Prefix' => '978-99937', 'Agency' => 'Macau', @@ -7645,7 +7747,7 @@ ), ), ), - 192 => + 194 => array ( 'Prefix' => '978-99938', 'Agency' => 'Srpska, Republic of', @@ -7676,7 +7778,7 @@ ), ), ), - 193 => + 195 => array ( 'Prefix' => '978-99939', 'Agency' => 'Guatemala', @@ -7702,7 +7804,7 @@ ), ), ), - 194 => + 196 => array ( 'Prefix' => '978-99940', 'Agency' => 'Georgia', @@ -7728,7 +7830,7 @@ ), ), ), - 195 => + 197 => array ( 'Prefix' => '978-99941', 'Agency' => 'Armenia', @@ -7754,7 +7856,7 @@ ), ), ), - 196 => + 198 => array ( 'Prefix' => '978-99942', 'Agency' => 'Sudan', @@ -7780,7 +7882,7 @@ ), ), ), - 197 => + 199 => array ( 'Prefix' => '978-99943', 'Agency' => 'Albania', @@ -7806,7 +7908,7 @@ ), ), ), - 198 => + 200 => array ( 'Prefix' => '978-99944', 'Agency' => 'Ethiopia', @@ -7832,7 +7934,7 @@ ), ), ), - 199 => + 201 => array ( 'Prefix' => '978-99945', 'Agency' => 'Namibia', @@ -7858,7 +7960,7 @@ ), ), ), - 200 => + 202 => array ( 'Prefix' => '978-99946', 'Agency' => 'Nepal', @@ -7884,7 +7986,7 @@ ), ), ), - 201 => + 203 => array ( 'Prefix' => '978-99947', 'Agency' => 'Tajikistan', @@ -7910,7 +8012,7 @@ ), ), ), - 202 => + 204 => array ( 'Prefix' => '978-99948', 'Agency' => 'Eritrea', @@ -7936,7 +8038,7 @@ ), ), ), - 203 => + 205 => array ( 'Prefix' => '978-99949', 'Agency' => 'Mauritius', @@ -7962,7 +8064,7 @@ ), ), ), - 204 => + 206 => array ( 'Prefix' => '978-99950', 'Agency' => 'Cambodia', @@ -7988,7 +8090,7 @@ ), ), ), - 205 => + 207 => array ( 'Prefix' => '978-99951', 'Agency' => 'Reserved Agency', @@ -8004,7 +8106,7 @@ ), ), ), - 206 => + 208 => array ( 'Prefix' => '978-99952', 'Agency' => 'Mali', @@ -8030,7 +8132,7 @@ ), ), ), - 207 => + 209 => array ( 'Prefix' => '978-99953', 'Agency' => 'Paraguay', @@ -8061,7 +8163,7 @@ ), ), ), - 208 => + 210 => array ( 'Prefix' => '978-99954', 'Agency' => 'Bolivia', @@ -8092,7 +8194,7 @@ ), ), ), - 209 => + 211 => array ( 'Prefix' => '978-99955', 'Agency' => 'Srpska, Republic of', @@ -8123,7 +8225,7 @@ ), ), ), - 210 => + 212 => array ( 'Prefix' => '978-99956', 'Agency' => 'Albania', @@ -8149,7 +8251,7 @@ ), ), ), - 211 => + 213 => array ( 'Prefix' => '978-99957', 'Agency' => 'Malta', @@ -8169,18 +8271,18 @@ ), 2 => array ( - 'Range' => '8000000-9599999', + 'Range' => '8000000-9499999', 'Length' => '3', ), 3 => array ( - 'Range' => '9600000-9999999', + 'Range' => '9500000-9999999', 'Length' => '2', ), ), ), ), - 212 => + 214 => array ( 'Prefix' => '978-99958', 'Agency' => 'Bahrain', @@ -8211,7 +8313,7 @@ ), ), ), - 213 => + 215 => array ( 'Prefix' => '978-99959', 'Agency' => 'Luxembourg', @@ -8237,7 +8339,7 @@ ), ), ), - 214 => + 216 => array ( 'Prefix' => '978-99960', 'Agency' => 'Malawi', @@ -8263,7 +8365,7 @@ ), ), ), - 215 => + 217 => array ( 'Prefix' => '978-99961', 'Agency' => 'El Salvador', @@ -8294,7 +8396,7 @@ ), ), ), - 216 => + 218 => array ( 'Prefix' => '978-99962', 'Agency' => 'Mongolia', @@ -8320,7 +8422,7 @@ ), ), ), - 217 => + 219 => array ( 'Prefix' => '978-99963', 'Agency' => 'Cambodia', @@ -8346,7 +8448,7 @@ ), ), ), - 218 => + 220 => array ( 'Prefix' => '978-99964', 'Agency' => 'Nicaragua', @@ -8372,7 +8474,7 @@ ), ), ), - 219 => + 221 => array ( 'Prefix' => '978-99965', 'Agency' => 'Macau', @@ -8403,7 +8505,7 @@ ), ), ), - 220 => + 222 => array ( 'Prefix' => '978-99966', 'Agency' => 'Kuwait', @@ -8439,7 +8541,7 @@ ), ), ), - 221 => + 223 => array ( 'Prefix' => '978-99967', 'Agency' => 'Paraguay', @@ -8490,7 +8592,7 @@ ), ), ), - 222 => + 224 => array ( 'Prefix' => '978-99968', 'Agency' => 'Botswana', @@ -8521,7 +8623,7 @@ ), ), ), - 223 => + 225 => array ( 'Prefix' => '978-99969', 'Agency' => 'Oman', @@ -8547,7 +8649,7 @@ ), ), ), - 224 => + 226 => array ( 'Prefix' => '978-99970', 'Agency' => 'Haiti', @@ -8573,7 +8675,7 @@ ), ), ), - 225 => + 227 => array ( 'Prefix' => '978-99971', 'Agency' => 'Myanmar', @@ -8599,7 +8701,7 @@ ), ), ), - 226 => + 228 => array ( 'Prefix' => '978-99972', 'Agency' => 'Faroe Islands', @@ -8625,7 +8727,7 @@ ), ), ), - 227 => + 229 => array ( 'Prefix' => '978-99973', 'Agency' => 'Mongolia', @@ -8651,7 +8753,7 @@ ), ), ), - 228 => + 230 => array ( 'Prefix' => '978-99974', 'Agency' => 'Bolivia', @@ -8676,10 +8778,20 @@ ), 3 => array ( - 'Range' => '4000000-7999999', + 'Range' => '4000000-6399999', 'Length' => '2', ), 4 => + array ( + 'Range' => '6400000-6499999', + 'Length' => '3', + ), + 5 => + array ( + 'Range' => '6500000-7999999', + 'Length' => '2', + ), + 6 => array ( 'Range' => '8000000-9999999', 'Length' => '3', @@ -8687,7 +8799,7 @@ ), ), ), - 229 => + 231 => array ( 'Prefix' => '978-99975', 'Agency' => 'Tajikistan', @@ -8718,7 +8830,7 @@ ), ), ), - 230 => + 232 => array ( 'Prefix' => '978-99976', 'Agency' => 'Srpska, Republic of', @@ -8749,7 +8861,7 @@ ), ), ), - 231 => + 233 => array ( 'Prefix' => '978-99977', 'Agency' => 'Rwanda', @@ -8785,7 +8897,7 @@ ), ), ), - 232 => + 234 => array ( 'Prefix' => '978-99978', 'Agency' => 'Mongolia', @@ -8811,7 +8923,7 @@ ), ), ), - 233 => + 235 => array ( 'Prefix' => '978-99979', 'Agency' => 'Honduras', @@ -8837,7 +8949,7 @@ ), ), ), - 234 => + 236 => array ( 'Prefix' => '978-99980', 'Agency' => 'Bhutan', @@ -8873,7 +8985,7 @@ ), ), ), - 235 => + 237 => array ( 'Prefix' => '978-99981', 'Agency' => 'Macau', @@ -8909,7 +9021,7 @@ ), ), ), - 236 => + 238 => array ( 'Prefix' => '978-99982', 'Agency' => 'Benin', @@ -8950,7 +9062,7 @@ ), ), ), - 237 => + 239 => array ( 'Prefix' => '979-10', 'Agency' => 'France', @@ -8986,7 +9098,7 @@ ), ), ), - 238 => + 240 => array ( 'Prefix' => '979-11', 'Agency' => 'Korea, Republic', @@ -9022,7 +9134,7 @@ ), ), ), - 239 => + 241 => array ( 'Prefix' => '979-12', 'Agency' => 'Italy', From c1e20f3012d5954cd78b87e15c0213f220417f03 Mon Sep 17 00:00:00 2001 From: Clement Bourgoin Date: Thu, 18 Apr 2019 17:03:16 +0200 Subject: [PATCH 11/11] Bump version to 2.1.0 & update changelog --- README.md | 11 +++++++++-- composer.json | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 590ff5d..a26ce19 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.org/biblys/isbn.svg?branch=master)](https://travis-ci.org/biblys/isbn) -This package can be used to : +This package can be used to: - validate an ISBN code - convert codes between ISBN-10, ISBN-13 and EAN (without hyphens) formats @@ -14,7 +14,7 @@ This package can be used to : Install with composer: ```console -composer require biblys/isbn:~2.0 +composer require biblys/isbn:^2.1.0 ``` ## Usage @@ -70,6 +70,13 @@ composer run update-ranges ## Changelog +### 2.1.0 (2019-04-18) + +- Added a `validate` method that throws an Exception on ISBN validation errors +- Fixed [#9] Improve error output +- Added composer scripts to run tests and update ranges in a Docker container +- Updated ISBN ranges + ### 2.0.8 (2019-02-07) - Fixed [#7](https://github.com/biblys/isbn/issues/7): ISBNs with invalid product diff --git a/composer.json b/composer.json index f3f9bfd..5cd17f1 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "biblys/isbn", "description": "A PHP library to convert and validate ISBNs & EANs", - "time": "2019-02-07", + "time": "2019-04-18", "keywords": [ "ISBN", "EAN",