Skip to content

Commit

Permalink
also make sure 1 character length is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
joonsp committed Nov 7, 2013
1 parent 5955d48 commit 813ac09
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions library/Xi/Algorithm/Luhn.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public function generate($number)
*/
public function validate($number)
{
if (strlen($number) < 2) {
return false;
}

$original = substr($number, 0, strlen($number) - 1);

return $this->generate($original) === $number;
Expand Down
1 change: 1 addition & 0 deletions tests/Xi/Tests/Algorithm/LuhnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public function luhnInvalidProvider()
array(799273983),
array(1231),
array(4565),
array(1),
);
}
}

0 comments on commit 813ac09

Please sign in to comment.