Skip to content

Commit

Permalink
Merge pull request #384 from owsy/encode-numeric-string
Browse files Browse the repository at this point in the history
Encoding Numeric Strings
  • Loading branch information
tedivm authored Feb 21, 2022
2 parents 8935156 + 858f9a3 commit 7a898d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Stash/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ public static function encoding($data)
return 'bool';
}

if (is_string($data)) {
return 'string';
}

if (is_numeric($data)) {
if (is_numeric($data) && ($data >= 2147483648 || $data < -2147483648)) {
return 'serialize';
} else {
return 'numeric';
}
}

return 'string';
}

return 'serialize';
Expand Down
2 changes: 2 additions & 0 deletions tests/Stash/Test/UtilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public function testEncoding()
$this->assertEquals(Utilities::encoding(true), 'bool', 'encoding recognized \'true\' boolean.');
$this->assertEquals(Utilities::encoding(false), 'bool', 'encoding recognized \'false\' boolean');

$this->assertEquals(Utilities::encoding('1'), 'string', 'encoding recognized \'1\' string.');
$this->assertEquals(Utilities::encoding('1.2'), 'string', 'encoding recognized \'1.2\' string.');
$this->assertEquals(Utilities::encoding('String of doom!'), 'string', 'encoding recognized string scalar');

$this->assertEquals(Utilities::encoding(234), 'numeric', 'encoding recognized integer scalar');
Expand Down

0 comments on commit 7a898d8

Please sign in to comment.