Skip to content

Commit b1f3dff

Browse files
committed
feat: remove increment/decrement functionality from storage adapters
As per #117, the increment and decrement functionality (at least decrement) leads to issues with several backends. This commit removes that functionality at all as it should be either part of specific adapters instead (via dedicated interface) or as part of project specific code. This cache component can not guarantee increment/decrement for all adapters out there (especially for adapters which do not support this feature natively to prevent race conditions). Signed-off-by: Maximilian Bösing <[email protected]>
1 parent 9cca821 commit b1f3dff

File tree

4 files changed

+0
-400
lines changed

4 files changed

+0
-400
lines changed

psalm-baseline.xml

-18
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,6 @@
308308
<code>$normalizedKey</code>
309309
<code>$normalizedKey</code>
310310
<code>$normalizedKey</code>
311-
<code>$value</code>
312-
<code>$value</code>
313311
</MixedArgument>
314312
<MixedArgumentTypeCoercion>
315313
<code>$key</code>
@@ -338,17 +336,11 @@
338336
<code>bool</code>
339337
<code>bool</code>
340338
<code>bool</code>
341-
<code>int|bool</code>
342-
<code>int|bool</code>
343-
<code>int|bool</code>
344-
<code>int|bool</code>
345339
</MixedInferredReturnType>
346340
<MixedMethodCall>
347341
<code>setAdapter</code>
348342
</MixedMethodCall>
349343
<MixedReturnStatement>
350-
<code>$newValue</code>
351-
<code>$newValue</code>
352344
<code><![CDATA[$this->options]]></code>
353345
<code><![CDATA[$this->triggerException(__FUNCTION__, $args, $keys, $e)]]></code>
354346
<code><![CDATA[$this->triggerException(__FUNCTION__, $args, $keys, $e)]]></code>
@@ -392,20 +384,12 @@
392384
<NullableReturnStatement>
393385
<code>$success</code>
394386
</NullableReturnStatement>
395-
<PossiblyInvalidArgument>
396-
<code><![CDATA[$args['key']]]></code>
397-
<code><![CDATA[$args['key']]]></code>
398-
<code><![CDATA[$args['value']]]></code>
399-
<code><![CDATA[$args['value']]]></code>
400-
</PossiblyInvalidArgument>
401387
<PossiblyUnusedMethod>
402388
<code>getCaching</code>
403389
<code>setCaching</code>
404390
</PossiblyUnusedMethod>
405391
<RedundantCastGivenDocblockType>
406392
<code>(bool) $flag</code>
407-
<code>(int) $value</code>
408-
<code>(int) $value</code>
409393
<code>(string) $key</code>
410394
</RedundantCastGivenDocblockType>
411395
</file>
@@ -672,8 +656,6 @@
672656
<file src="src/Storage/StorageInterface.php">
673657
<PossiblyUnusedMethod>
674658
<code>addItem</code>
675-
<code>decrementItem</code>
676-
<code>incrementItem</code>
677659
<code>replaceItem</code>
678660
<code>touchItem</code>
679661
</PossiblyUnusedMethod>

src/Storage/Adapter/AbstractAdapter.php

-228
Original file line numberDiff line numberDiff line change
@@ -1097,234 +1097,6 @@ protected function internalRemoveItems(array &$normalizedKeys)
10971097
return $result;
10981098
}
10991099

1100-
/**
1101-
* Increment an item.
1102-
*
1103-
* @param string $key
1104-
* @param int $value
1105-
* @return int|bool The new value on success, false on failure
1106-
* @throws Exception\ExceptionInterface
1107-
* @triggers incrementItem.pre(PreEvent)
1108-
* @triggers incrementItem.post(PostEvent)
1109-
* @triggers incrementItem.exception(ExceptionEvent)
1110-
*/
1111-
public function incrementItem($key, $value)
1112-
{
1113-
if (! $this->getOptions()->getWritable()) {
1114-
return false;
1115-
}
1116-
1117-
$this->normalizeKey($key);
1118-
$args = new ArrayObject([
1119-
'key' => &$key,
1120-
'value' => &$value,
1121-
]);
1122-
1123-
try {
1124-
$eventRs = $this->triggerPre(__FUNCTION__, $args);
1125-
1126-
$result = $eventRs->stopped()
1127-
? $eventRs->last()
1128-
: $this->internalIncrementItem($args['key'], $args['value']);
1129-
1130-
return $this->triggerPost(__FUNCTION__, $args, $result);
1131-
} catch (\Exception $e) {
1132-
$result = false;
1133-
return $this->triggerException(__FUNCTION__, $args, $result, $e);
1134-
}
1135-
}
1136-
1137-
/**
1138-
* Internal method to increment an item.
1139-
*
1140-
* @param string $normalizedKey
1141-
* @param int $value
1142-
* @return int|bool The new value on success, false on failure
1143-
* @throws Exception\ExceptionInterface
1144-
*/
1145-
protected function internalIncrementItem(&$normalizedKey, &$value)
1146-
{
1147-
$success = null;
1148-
$value = (int) $value;
1149-
$get = (int) $this->internalGetItem($normalizedKey, $success);
1150-
$newValue = $get + $value;
1151-
1152-
if ($success) {
1153-
$this->internalReplaceItem($normalizedKey, $newValue);
1154-
} else {
1155-
$this->internalAddItem($normalizedKey, $newValue);
1156-
}
1157-
1158-
return $newValue;
1159-
}
1160-
1161-
/**
1162-
* Increment multiple items.
1163-
*
1164-
* @param array $keyValuePairs
1165-
* @return array Associative array of keys and new values
1166-
* @throws Exception\ExceptionInterface
1167-
* @triggers incrementItems.pre(PreEvent)
1168-
* @triggers incrementItems.post(PostEvent)
1169-
* @triggers incrementItems.exception(ExceptionEvent)
1170-
*/
1171-
public function incrementItems(array $keyValuePairs)
1172-
{
1173-
if (! $this->getOptions()->getWritable()) {
1174-
return [];
1175-
}
1176-
1177-
$this->normalizeKeyValuePairs($keyValuePairs);
1178-
$args = new ArrayObject([
1179-
'keyValuePairs' => &$keyValuePairs,
1180-
]);
1181-
1182-
try {
1183-
$eventRs = $this->triggerPre(__FUNCTION__, $args);
1184-
1185-
$result = $eventRs->stopped()
1186-
? $eventRs->last()
1187-
: $this->internalIncrementItems($args['keyValuePairs']);
1188-
1189-
return $this->triggerPost(__FUNCTION__, $args, $result);
1190-
} catch (\Exception $e) {
1191-
$result = [];
1192-
return $this->triggerException(__FUNCTION__, $args, $result, $e);
1193-
}
1194-
}
1195-
1196-
/**
1197-
* Internal method to increment multiple items.
1198-
*
1199-
* @return array Associative array of keys and new values
1200-
* @throws Exception\ExceptionInterface
1201-
*/
1202-
protected function internalIncrementItems(array &$normalizedKeyValuePairs)
1203-
{
1204-
$result = [];
1205-
foreach ($normalizedKeyValuePairs as $normalizedKey => $value) {
1206-
$newValue = $this->internalIncrementItem($normalizedKey, $value);
1207-
if ($newValue !== false) {
1208-
$result[$normalizedKey] = $newValue;
1209-
}
1210-
}
1211-
return $result;
1212-
}
1213-
1214-
/**
1215-
* Decrement an item.
1216-
*
1217-
* @param string $key
1218-
* @param int $value
1219-
* @return int|bool The new value on success, false on failure
1220-
* @throws Exception\ExceptionInterface
1221-
* @triggers decrementItem.pre(PreEvent)
1222-
* @triggers decrementItem.post(PostEvent)
1223-
* @triggers decrementItem.exception(ExceptionEvent)
1224-
*/
1225-
public function decrementItem($key, $value)
1226-
{
1227-
if (! $this->getOptions()->getWritable()) {
1228-
return false;
1229-
}
1230-
1231-
$this->normalizeKey($key);
1232-
$args = new ArrayObject([
1233-
'key' => &$key,
1234-
'value' => &$value,
1235-
]);
1236-
1237-
try {
1238-
$eventRs = $this->triggerPre(__FUNCTION__, $args);
1239-
1240-
$result = $eventRs->stopped()
1241-
? $eventRs->last()
1242-
: $this->internalDecrementItem($args['key'], $args['value']);
1243-
1244-
return $this->triggerPost(__FUNCTION__, $args, $result);
1245-
} catch (\Exception $e) {
1246-
$result = false;
1247-
return $this->triggerException(__FUNCTION__, $args, $result, $e);
1248-
}
1249-
}
1250-
1251-
/**
1252-
* Internal method to decrement an item.
1253-
*
1254-
* @param string $normalizedKey
1255-
* @param int $value
1256-
* @return int|bool The new value on success, false on failure
1257-
* @throws Exception\ExceptionInterface
1258-
*/
1259-
protected function internalDecrementItem(&$normalizedKey, &$value)
1260-
{
1261-
$success = null;
1262-
$value = (int) $value;
1263-
$get = (int) $this->internalGetItem($normalizedKey, $success);
1264-
$newValue = $get - $value;
1265-
1266-
if ($success) {
1267-
$this->internalReplaceItem($normalizedKey, $newValue);
1268-
} else {
1269-
$this->internalAddItem($normalizedKey, $newValue);
1270-
}
1271-
1272-
return $newValue;
1273-
}
1274-
1275-
/**
1276-
* Decrement multiple items.
1277-
*
1278-
* @param array $keyValuePairs
1279-
* @return array Associative array of keys and new values
1280-
* @throws Exception\ExceptionInterface
1281-
* @triggers incrementItems.pre(PreEvent)
1282-
* @triggers incrementItems.post(PostEvent)
1283-
* @triggers incrementItems.exception(ExceptionEvent)
1284-
*/
1285-
public function decrementItems(array $keyValuePairs)
1286-
{
1287-
if (! $this->getOptions()->getWritable()) {
1288-
return [];
1289-
}
1290-
1291-
$this->normalizeKeyValuePairs($keyValuePairs);
1292-
$args = new ArrayObject([
1293-
'keyValuePairs' => &$keyValuePairs,
1294-
]);
1295-
1296-
try {
1297-
$eventRs = $this->triggerPre(__FUNCTION__, $args);
1298-
1299-
$result = $eventRs->stopped()
1300-
? $eventRs->last()
1301-
: $this->internalDecrementItems($args['keyValuePairs']);
1302-
1303-
return $this->triggerPost(__FUNCTION__, $args, $result);
1304-
} catch (\Exception $e) {
1305-
$result = [];
1306-
return $this->triggerException(__FUNCTION__, $args, $result, $e);
1307-
}
1308-
}
1309-
1310-
/**
1311-
* Internal method to decrement multiple items.
1312-
*
1313-
* @return array Associative array of keys and new values
1314-
* @throws Exception\ExceptionInterface
1315-
*/
1316-
protected function internalDecrementItems(array &$normalizedKeyValuePairs)
1317-
{
1318-
$result = [];
1319-
foreach ($normalizedKeyValuePairs as $normalizedKey => $value) {
1320-
$newValue = $this->internalDecrementItem($normalizedKey, $value);
1321-
if ($newValue !== false) {
1322-
$result[$normalizedKey] = $newValue;
1323-
}
1324-
}
1325-
return $result;
1326-
}
1327-
13281100
/* status */
13291101

13301102
/**

src/Storage/StorageInterface.php

-36
Original file line numberDiff line numberDiff line change
@@ -159,42 +159,6 @@ public function removeItem($key);
159159
*/
160160
public function removeItems(array $keys);
161161

162-
/**
163-
* Increment an item.
164-
*
165-
* @param string $key
166-
* @param int $value
167-
* @return int|bool The new value on success, false on failure
168-
* @throws ExceptionInterface
169-
*/
170-
public function incrementItem($key, $value);
171-
172-
/**
173-
* Increment multiple items.
174-
*
175-
* @return array Associative array of keys and new values
176-
* @throws ExceptionInterface
177-
*/
178-
public function incrementItems(array $keyValuePairs);
179-
180-
/**
181-
* Decrement an item.
182-
*
183-
* @param string $key
184-
* @param int $value
185-
* @return int|bool The new value on success, false on failure
186-
* @throws ExceptionInterface
187-
*/
188-
public function decrementItem($key, $value);
189-
190-
/**
191-
* Decrement multiple items.
192-
*
193-
* @return array Associative array of keys and new values
194-
* @throws ExceptionInterface
195-
*/
196-
public function decrementItems(array $keyValuePairs);
197-
198162
/* status */
199163

200164
/**

0 commit comments

Comments
 (0)