-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert ISBN10 to ISBN13 and change add to add_if_new #205
Conversation
Codecov Report
@@ Coverage Diff @@
## development #205 +/- ##
=================================================
+ Coverage 65.72% 71.99% +6.26%
- Complexity 1201 1212 +11
=================================================
Files 8 8
Lines 2343 2278 -65
=================================================
+ Hits 1540 1640 +100
+ Misses 803 638 -165
Continue to review full report at Codecov.
|
Unless there are circumstances when one might want to add an ISBN without undergoing this check, my suggestion would be to call the function once from within add_if_new, rather than each time add_if_new is called. One fewer thing to remember when adding calls in the future, it catches cases where the parameter name is now hard-coded (e.g. conversion of ID parameter), and it keeps all the handy format checks in one place. |
I will do that |
This fails the quality control because add_if_new correctly sets the "year" parameter instead of the "date" parameter. |
This is now called in add_if_new |
I think this is done now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small error in regexp syntax
Template.php
Outdated
public function isbn10Toisbn13 ($isbn10) { | ||
$isbn10 = trim($isbn10); // Remove leading and trailing spaces | ||
$isbn10 = str_replace(array('—','―','–','−','‒'),'-', $isbn10); // standardize dahses : en dash, horizontal bar, em dash, minus sign, figure dash, to hyphen. | ||
if (preg_match("/[^0123456789Xx-]/",$isbn10) === 1) return $isbn10; // Contains invalid characters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to escape the hyphen.
"/[^0123456789Xx\-]/"
Or more concisely
"/[^0-9Xx\-]/"
For consistency I'd also suggest using ~
instead of /
as the regular expression delimiter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you able to add a test case too, please?
No description provided.