From 02f3cc739fbe627cb3d4a53ba0834f320410cd33 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Fri, 10 May 2019 22:46:39 +0200 Subject: [PATCH] documentation on fnv1a64 is lacking, but tests show it was only introduced with PHP 5.6 --- lib/Model/AbstractModel.php | 2 +- tst/Data/DatabaseTest.php | 2 +- tst/Data/FilesystemTest.php | 2 +- tst/ModelTest.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Model/AbstractModel.php b/lib/Model/AbstractModel.php index 87bf2b35..8190c13e 100644 --- a/lib/Model/AbstractModel.php +++ b/lib/Model/AbstractModel.php @@ -108,7 +108,7 @@ abstract class AbstractModel $this->_data = $data; // calculate a 64 bit checksum to avoid collisions - $this->setId(hash('fnv1a64', $data['ct'])); + $this->setId(hash(version_compare(PHP_VERSION, '5.5') > 0 ? 'fnv1a64' : 'fnv164', $data['ct'])); } /** diff --git a/tst/Data/DatabaseTest.php b/tst/Data/DatabaseTest.php index 7e62e5f4..0d48eb6a 100644 --- a/tst/Data/DatabaseTest.php +++ b/tst/Data/DatabaseTest.php @@ -98,7 +98,7 @@ class DatabaseTest extends PHPUnit_Framework_TestCase $keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'x', 'y', 'z'); $ids = array(); foreach ($keys as $key) { - $ids[$key] = hash('fnv1a64', $key); + $ids[$key] = hash('fnv164', $key); $this->_model->delete($ids[$key]); $this->assertFalse($this->_model->exists($ids[$key]), "paste $key does not yet exist"); if (in_array($key, array('y', 'z'))) { diff --git a/tst/Data/FilesystemTest.php b/tst/Data/FilesystemTest.php index d4d6ec06..37e03f36 100644 --- a/tst/Data/FilesystemTest.php +++ b/tst/Data/FilesystemTest.php @@ -88,7 +88,7 @@ class FilesystemTest extends PHPUnit_Framework_TestCase $keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'x', 'y', 'z'); $ids = array(); foreach ($keys as $key) { - $ids[$key] = hash('fnv1a64', $key); + $ids[$key] = hash('fnv164', $key); $this->assertFalse($this->_model->exists($ids[$key]), "paste $key does not yet exist"); if (in_array($key, array('x', 'y', 'z'))) { $this->assertTrue($this->_model->create($ids[$key], $paste), "store $key paste"); diff --git a/tst/ModelTest.php b/tst/ModelTest.php index 5a0006da..c04ea393 100644 --- a/tst/ModelTest.php +++ b/tst/ModelTest.php @@ -284,7 +284,7 @@ class ModelTest extends PHPUnit_Framework_TestCase $keys = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'x', 'y', 'z'); $ids = array(); foreach ($keys as $key) { - $ids[$key] = hash('fnv1a64', $key); + $ids[$key] = hash('fnv164', $key); $store->delete($ids[$key]); $this->assertFalse($store->exists($ids[$key]), "paste $key does not yet exist"); if (in_array($key, array('x', 'y', 'z'))) {