Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
fixed #66 by reducing variable references
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-mabe committed Feb 12, 2016
1 parent 31c45e1 commit c927478
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/Storage/Adapter/Apc.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ protected function internalGetItems(array & $normalizedKeys)
// remove namespace prefix
$prefixL = strlen($prefix);
$result = [];
foreach ($fetch as $internalKey => & $value) {
foreach ($fetch as $internalKey => $value) {
$result[substr($internalKey, $prefixL)] = $value;
}

Expand Down Expand Up @@ -432,9 +432,9 @@ protected function internalSetItems(array & $normalizedKeyValuePairs)

$prefix = $namespace . $options->getNamespaceSeparator();
$internalKeyValuePairs = [];
foreach ($normalizedKeyValuePairs as $normalizedKey => &$value) {
foreach ($normalizedKeyValuePairs as $normalizedKey => $value) {
$internalKey = $prefix . $normalizedKey;
$internalKeyValuePairs[$internalKey] = &$value;
$internalKeyValuePairs[$internalKey] = $value;
}

$failedKeys = apc_store($internalKeyValuePairs, null, $options->getTtl());
Expand Down
8 changes: 4 additions & 4 deletions src/Storage/Adapter/Memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ protected function internalGetItems(array & $normalizedKeys)
if ($result && $this->namespacePrefix !== '') {
$tmp = [];
$nsPrefixLength = strlen($this->namespacePrefix);
foreach ($result as $internalKey => & $value) {
$tmp[substr($internalKey, $nsPrefixLength)] = & $value;
foreach ($result as $internalKey => $value) {
$tmp[substr($internalKey, $nsPrefixLength)] = $value;
}
$result = $tmp;
}
Expand Down Expand Up @@ -399,8 +399,8 @@ protected function internalSetItems(array & $normalizedKeyValuePairs)
$expiration = $this->expirationTime();

$namespacedKeyValuePairs = [];
foreach ($normalizedKeyValuePairs as $normalizedKey => & $value) {
$namespacedKeyValuePairs[$this->namespacePrefix . $normalizedKey] = & $value;
foreach ($normalizedKeyValuePairs as $normalizedKey => $value) {
$namespacedKeyValuePairs[$this->namespacePrefix . $normalizedKey] = $value;
}

if (!$memc->setMulti($namespacedKeyValuePairs, $expiration)) {
Expand Down
44 changes: 44 additions & 0 deletions test/Storage/Adapter/CommonAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,28 @@ public function testIncrementItemReturnsFalseIfNonWritable()
$this->assertEquals(10, $this->_storage->getItem('key'));
}

/**
* @link https://github.com/zendframework/zend-cache/issues/66
*/
public function testSetAndIncrementItems()
{
$this->_storage->setItems([
'key1' => 10,
'key2' => 11,
]);

$result = $this->_storage->incrementItems([
'key1' => 10,
'key2' => 20,
]);
ksort($result);

$this->assertSame([
'key1' => 20,
'key2' => 31,
], $result);
}

public function testIncrementItemsResturnsKeyValuePairsOfWrittenItems()
{
$this->assertTrue($this->_storage->setItem('key1', 10));
Expand Down Expand Up @@ -875,6 +897,28 @@ public function testDecrementItemReturnsFalseIfNonWritable()
$this->assertEquals(10, $this->_storage->getItem('key'));
}

/**
* @link https://github.com/zendframework/zend-cache/issues/66
*/
public function testSetAndDecrementItems()
{
$this->_storage->setItems([
'key1' => 10,
'key2' => 11,
]);

$result = $this->_storage->decrementItems([
'key1' => 10,
'key2' => 5,
]);
ksort($result);

$this->assertSame([
'key1' => 0,
'key2' => 6,
], $result);
}

public function testDecrementItemsReturnsEmptyArrayIfNonWritable()
{
$this->_storage->setItem('key', 10);
Expand Down

0 comments on commit c927478

Please sign in to comment.