Skip to content

Commit

Permalink
Merge branch 'release/2.1.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlatz committed Feb 28, 2020
2 parents 8214df2 + 643924e commit ed8587e
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 193 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This package can be used to:
Install with composer:

```console
composer require biblys/isbn:^2.1.3
composer require biblys/isbn:^2.1.4
```

## Usage
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "biblys/isbn",
"description": "A PHP library to convert and validate ISBNs & EANs",
"time": "2020-01-09",
"time": "2020-02-28",
"keywords": [
"ISBN",
"EAN",
Expand Down
48 changes: 23 additions & 25 deletions src/Biblys/Isbn/Isbn.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,35 @@ class Isbn

public function __construct($code = null)
{
if (!empty($code)) {
$this->_input = $code;
$this->_input = $code;

// Remove hyphens and check characters
$code = $this->removeHyphens($code);

// Remove checksum and check length
$code = $this->removeChecksum($code);
// If input is empty
if (empty($code)) {
$this->addError(static::ERROR_EMPTY);
$this->setValid(false);
return;
}

if ($this->isValid()) {
// Remove (and set) product code
$code = $this->removeProductCode($code);
// Remove hyphens and check characters
$code = $this->removeHyphens($code);

// Remove (and save) country code
$code = $this->removeCountryCode($code);
// Remove checksum and check length
$code = $this->removeChecksum($code);

// Remove (and save) publisher code
$this->removePublisherCode($code);
}
} else {
$this->addError(static::ERROR_EMPTY);
// At that point, code should be digits only
if (!is_numeric($code)) {
$this->setValid(false);
$this->addError(static::ERROR_INVALID_CHARACTERS);
}

// Remove (and save) product code
$code = $this->removeProductCode($code);

// Remove (and save) country code
$code = $this->removeCountryCode($code);

// Remove (and save) publisher code
$this->removePublisherCode($code);
}

/**
Expand Down Expand Up @@ -156,14 +162,6 @@ private function removeHyphens($code)
$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(static::ERROR_INVALID_CHARACTERS);
}

return $code;
}

Expand Down
Loading

0 comments on commit ed8587e

Please sign in to comment.