Skip to content

Commit

Permalink
fixing notice when passing empty array to encode
Browse files Browse the repository at this point in the history
  • Loading branch information
4kimov committed Jan 21, 2015
1 parent be7411f commit 4412483
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/Hashids/Hashids.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class Hashids implements HashGenerator {

const VERSION = '1.0.4';
const VERSION = '1.0.5';

/* internal settings */

Expand Down Expand Up @@ -120,14 +120,14 @@ public function encode() {
$ret = '';
$numbers = func_get_args();

if (!$numbers) {
return $ret;
}

if (func_num_args() == 1 && is_array(func_get_arg(0))) {
$numbers = $numbers[0];
}

if (!$numbers) {
return $ret;
}

foreach ($numbers as $number) {

$is_number = ctype_digit((string)$number);
Expand Down
12 changes: 11 additions & 1 deletion tests/HashidsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function testMinHashLength() {

}

public function testRandomHashesdecodeion() {
public function testRandomHashesDecoding() {

$corrupt = $hashes = array();

Expand Down Expand Up @@ -170,6 +170,16 @@ public function testNegativeValue() {
$this->assertEquals('', $hash);
}

public function testEncodingEmptyArray() {
$hash = $this->hashids->encode(array());
$this->assertEquals('', $hash);
}

public function testEncodingWithoutParams() {
$hash = $this->hashids->encode();
$this->assertEquals('', $hash);
}

public function testEncodingDecodingHex() {

$testValue = '3ade68b1000fff';
Expand Down

0 comments on commit 4412483

Please sign in to comment.