Skip to content

Commit 5d3acf6

Browse files
committed
- Replaced \InvalidArgumentException occurrences with phpFastCacheInvalidArgumentException
1 parent 464201c commit 5d3acf6

File tree

4 files changed

+65
-60
lines changed

4 files changed

+65
-60
lines changed

src/phpFastCache/Core/Pool/ExtendedCacheItemPoolInterface.php

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Psr\Cache\CacheItemInterface;
2222
use Psr\Cache\CacheItemPoolInterface;
2323
use phpFastCache\Exceptions\phpFastCacheLogicException;
24+
use phpFastCache\Exceptions\phpFastCacheInvalidArgumentException;
2425

2526
/**
2627
* Interface ExtendedCacheItemPoolInterface
@@ -76,8 +77,8 @@ public function getDriverName();
7677
* @param string $key
7778
* The key for which to return the corresponding Cache Item.
7879
*
79-
* @throws InvalidArgumentException
80-
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
80+
* @throws phpFastCacheInvalidArgumentException
81+
* If the $key string is not a legal value a phpFastCacheInvalidArgumentException
8182
* MUST be thrown.
8283
*
8384
* @return ExtendedCacheItemInterface
@@ -93,7 +94,7 @@ public function getItem($key);
9394
* An indexed array of keys of items to retrieve.
9495
*
9596
* @throws InvalidArgumentException
96-
* If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
97+
* If any of the keys in $keys are not a legal value a phpFastCacheInvalidArgumentException
9798
* MUST be thrown.
9899
*
99100
* @return ExtendedCacheItemInterface[]
@@ -113,7 +114,7 @@ public function getItems(array $keys = []);
113114
* @param int $depth json_encode() depth
114115
*
115116
* @throws InvalidArgumentException
116-
* If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
117+
* If any of the keys in $keys are not a legal value a phpFastCacheInvalidArgumentException
117118
* MUST be thrown.
118119
*
119120
* @return string
@@ -147,7 +148,7 @@ public function getHelp();
147148
* An indexed array of keys of items to retrieve.
148149
*
149150
* @throws InvalidArgumentException
150-
* If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
151+
* If any of the keys in $keys are not a legal value a phpFastCacheInvalidArgumentException
151152
* MUST be thrown.
152153
*
153154
* @return ExtendedCacheItemInterface[]
@@ -165,7 +166,7 @@ public function getItemsByTag($tagName);
165166
* An indexed array of keys of items to retrieve.
166167
*
167168
* @throws InvalidArgumentException
168-
* If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
169+
* If any of the keys in $keys are not a legal value a phpFastCacheInvalidArgumentException
169170
* MUST be thrown.
170171
*
171172
* @return ExtendedCacheItemInterface[]
@@ -183,7 +184,7 @@ public function getItemsByTags(array $tagNames);
183184
* An indexed array of keys of items to retrieve.
184185
*
185186
* @throws InvalidArgumentException
186-
* If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
187+
* If any of the keys in $keys are not a legal value a phpFastCacheInvalidArgumentException
187188
* MUST be thrown.
188189
*
189190
* @return ExtendedCacheItemInterface[]
@@ -203,7 +204,7 @@ public function getItemsByTagsAll(array $tagNames);
203204
* @param int $depth json_encode() depth
204205
*
205206
* @throws InvalidArgumentException
206-
* If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
207+
* If any of the keys in $keys are not a legal value a phpFastCacheInvalidArgumentException
207208
* MUST be thrown.
208209
*
209210
* @return string
@@ -217,7 +218,7 @@ public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth
217218
* The tag for which to delete
218219
*
219220
* @throws InvalidArgumentException
220-
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
221+
* If the $key string is not a legal value a phpFastCacheInvalidArgumentException
221222
* MUST be thrown.
222223
*
223224
* @return bool
@@ -232,7 +233,7 @@ public function deleteItemsByTag($tagName);
232233
* The tag for which to delete
233234
*
234235
* @throws InvalidArgumentException
235-
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
236+
* If the $key string is not a legal value a phpFastCacheInvalidArgumentException
236237
* MUST be thrown.
237238
*
238239
* @return bool
@@ -247,7 +248,7 @@ public function deleteItemsByTags(array $tagNames);
247248
* An indexed array of keys of items to retrieve.
248249
*
249250
* @throws InvalidArgumentException
250-
* If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
251+
* If any of the keys in $keys are not a legal value a phpFastCacheInvalidArgumentException
251252
* MUST be thrown.
252253
*
253254
* @return bool
@@ -264,7 +265,7 @@ public function deleteItemsByTagsAll(array $tagNames);
264265
* @param int $step
265266
*
266267
* @throws InvalidArgumentException
267-
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
268+
* If the $key string is not a legal value a phpFastCacheInvalidArgumentException
268269
* MUST be thrown.
269270
*
270271
* @return bool
@@ -281,7 +282,7 @@ public function incrementItemsByTag($tagName, $step = 1);
281282
* @param int $step
282283
*
283284
* @throws InvalidArgumentException
284-
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
285+
* If the $key string is not a legal value a phpFastCacheInvalidArgumentException
285286
* MUST be thrown.
286287
*
287288
* @return bool
@@ -298,7 +299,7 @@ public function incrementItemsByTags(array $tagNames, $step = 1);
298299
* @param int $step
299300
*
300301
* @throws InvalidArgumentException
301-
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
302+
* If the $key string is not a legal value a phpFastCacheInvalidArgumentException
302303
* MUST be thrown.
303304
*
304305
* @return bool
@@ -315,7 +316,7 @@ public function incrementItemsByTagsAll(array $tagNames, $step = 1);
315316
* @param int $step
316317
*
317318
* @throws InvalidArgumentException
318-
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
319+
* If the $key string is not a legal value a phpFastCacheInvalidArgumentException
319320
* MUST be thrown.
320321
*
321322
* @return bool
@@ -332,7 +333,7 @@ public function decrementItemsByTag($tagName, $step = 1);
332333
* @param int $step
333334
*
334335
* @throws InvalidArgumentException
335-
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
336+
* If the $key string is not a legal value a phpFastCacheInvalidArgumentException
336337
* MUST be thrown.
337338
*
338339
* @return bool
@@ -349,7 +350,7 @@ public function decrementItemsByTags(array $tagNames, $step = 1);
349350
* @param int $step
350351
*
351352
* @throws InvalidArgumentException
352-
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
353+
* If the $key string is not a legal value a phpFastCacheInvalidArgumentException
353354
* MUST be thrown.
354355
*
355356
* @return bool
@@ -366,7 +367,7 @@ public function decrementItemsByTagsAll(array $tagNames, $step = 1);
366367
* @param array|string $data
367368
*
368369
* @throws InvalidArgumentException
369-
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
370+
* If the $key string is not a legal value a phpFastCacheInvalidArgumentException
370371
* MUST be thrown.
371372
*
372373
* @return bool
@@ -383,7 +384,7 @@ public function appendItemsByTag($tagName, $data);
383384
* @param array|string $data
384385
*
385386
* @throws InvalidArgumentException
386-
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
387+
* If the $key string is not a legal value a phpFastCacheInvalidArgumentException
387388
* MUST be thrown.
388389
*
389390
* @return bool
@@ -400,7 +401,7 @@ public function appendItemsByTags(array $tagNames, $data);
400401
* @param array|string $data
401402
*
402403
* @throws InvalidArgumentException
403-
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
404+
* If the $key string is not a legal value a phpFastCacheInvalidArgumentException
404405
* MUST be thrown.
405406
*
406407
* @return bool
@@ -417,7 +418,7 @@ public function appendItemsByTagsAll(array $tagNames, $data);
417418
* @param array|string $data
418419
*
419420
* @throws InvalidArgumentException
420-
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
421+
* If the $key string is not a legal value a phpFastCacheInvalidArgumentException
421422
* MUST be thrown.
422423
*
423424
* @return bool
@@ -434,7 +435,7 @@ public function prependItemsByTag($tagName, $data);
434435
* @param array|string $data
435436
*
436437
* @throws InvalidArgumentException
437-
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
438+
* If the $key string is not a legal value a phpFastCacheInvalidArgumentException
438439
* MUST be thrown.
439440
*
440441
* @return bool
@@ -451,7 +452,7 @@ public function prependItemsByTags(array $tagNames, $data);
451452
* @param array|string $data
452453
*
453454
* @throws InvalidArgumentException
454-
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
455+
* If the $key string is not a legal value a phpFastCacheInvalidArgumentException
455456
* MUST be thrown.
456457
*
457458
* @return bool

src/phpFastCache/Core/Pool/ExtendedCacheItemPoolTrait.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function getItemsByTag($tagName)
6464
return [];
6565
}
6666
} else {
67-
throw new InvalidArgumentException('$tagName must be a string');
67+
throw new phpFastCacheInvalidArgumentException('$tagName must be a string');
6868
}
6969
}
7070

@@ -78,7 +78,7 @@ public function getItemsByTags(array $tagNames)
7878
if(is_string($tagName)){
7979
$items = array_merge($items, $this->getItemsByTag($tagName));
8080
}else{
81-
throw new InvalidArgumentException('$tagName must be a a string');
81+
throw new phpFastCacheInvalidArgumentException('$tagName must be a a string');
8282
}
8383
}
8484

@@ -131,7 +131,7 @@ public function deleteItemsByTag($tagName)
131131

132132
return $return;
133133
} else {
134-
throw new InvalidArgumentException('$tagName must be a string');
134+
throw new phpFastCacheInvalidArgumentException('$tagName must be a string');
135135
}
136136
}
137137

@@ -182,7 +182,7 @@ public function incrementItemsByTag($tagName, $step = 1)
182182

183183
return $this->commit();
184184
} else {
185-
throw new InvalidArgumentException('$tagName must be a string and $step an integer');
185+
throw new phpFastCacheInvalidArgumentException('$tagName must be a string and $step an integer');
186186
}
187187
}
188188

@@ -216,7 +216,7 @@ public function incrementItemsByTagsAll(array $tagNames, $step = 1)
216216
}
217217
return $this->commit();
218218
} else {
219-
throw new InvalidArgumentException('$step must be an integer');
219+
throw new phpFastCacheInvalidArgumentException('$step must be an integer');
220220
}
221221
}
222222

@@ -233,7 +233,7 @@ public function decrementItemsByTag($tagName, $step = 1)
233233

234234
return $this->commit();
235235
} else {
236-
throw new InvalidArgumentException('$tagName must be a string and $step an integer');
236+
throw new phpFastCacheInvalidArgumentException('$tagName must be a string and $step an integer');
237237
}
238238
}
239239

@@ -267,7 +267,7 @@ public function decrementItemsByTagsAll(array $tagNames, $step = 1)
267267
}
268268
return $this->commit();
269269
} else {
270-
throw new InvalidArgumentException('$step must be an integer');
270+
throw new phpFastCacheInvalidArgumentException('$step must be an integer');
271271
}
272272
}
273273

@@ -284,7 +284,7 @@ public function appendItemsByTag($tagName, $data)
284284

285285
return $this->commit();
286286
} else {
287-
throw new InvalidArgumentException('$tagName must be a string');
287+
throw new phpFastCacheInvalidArgumentException('$tagName must be a string');
288288
}
289289
}
290290

@@ -318,7 +318,7 @@ public function appendItemsByTagsAll(array $tagNames, $data)
318318
}
319319
return $this->commit();
320320
} else {
321-
throw new InvalidArgumentException('$data must be scalar');
321+
throw new phpFastCacheInvalidArgumentException('$data must be scalar');
322322
}
323323
}
324324

@@ -335,7 +335,7 @@ public function prependItemsByTag($tagName, $data)
335335

336336
return $this->commit();
337337
} else {
338-
throw new InvalidArgumentException('$tagName must be a string');
338+
throw new phpFastCacheInvalidArgumentException('$tagName must be a string');
339339
}
340340
}
341341

@@ -369,7 +369,7 @@ public function prependItemsByTagsAll(array $tagNames, $data)
369369
}
370370
return $this->commit();
371371
} else {
372-
throw new InvalidArgumentException('$data must be scalar');
372+
throw new phpFastCacheInvalidArgumentException('$data must be scalar');
373373
}
374374
}
375375

src/phpFastCache/Drivers/Cassandra/Driver.php

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,29 @@ public function driverCheck()
6565
* @param \Psr\Cache\CacheItemInterface $item
6666
* @return mixed
6767
* @throws phpFastCacheInvalidArgumentException
68-
* @throws \Cassandra\Exception\InvalidArgumentException
6968
*/
7069
protected function driverWrite(CacheItemInterface $item)
7170
{
7271
/**
7372
* Check for Cross-Driver type confusion
7473
*/
7574
if ($item instanceof Item) {
76-
$cacheData = $this->encode($this->driverPreWrap($item));
77-
$options = new Cassandra\ExecutionOptions([
78-
'arguments' => [
79-
'cache_uuid' => new Cassandra\Uuid(),
80-
'cache_id' => $item->getKey(),
81-
'cache_data' => $cacheData,
82-
'cache_creation_date' => new Cassandra\Timestamp((new \DateTime())->getTimestamp()),
83-
'cache_expiration_date' => new Cassandra\Timestamp($item->getExpirationDate()->getTimestamp()),
84-
'cache_length' => strlen($cacheData)
85-
],
86-
'consistency' => Cassandra::CONSISTENCY_ALL,
87-
'serial_consistency' => Cassandra::CONSISTENCY_SERIAL
88-
]);
75+
try{
76+
$cacheData = $this->encode($this->driverPreWrap($item));
77+
$options = new Cassandra\ExecutionOptions([
78+
'arguments' => [
79+
'cache_uuid' => new Cassandra\Uuid(),
80+
'cache_id' => $item->getKey(),
81+
'cache_data' => $cacheData,
82+
'cache_creation_date' => new Cassandra\Timestamp((new \DateTime())->getTimestamp()),
83+
'cache_expiration_date' => new Cassandra\Timestamp($item->getExpirationDate()->getTimestamp()),
84+
'cache_length' => strlen($cacheData)
85+
],
86+
'consistency' => Cassandra::CONSISTENCY_ALL,
87+
'serial_consistency' => Cassandra::CONSISTENCY_SERIAL
88+
]);
8989

90-
$query = sprintf('INSERT INTO %s.%s
90+
$query = sprintf('INSERT INTO %s.%s
9191
(
9292
cache_uuid,
9393
cache_id,
@@ -99,13 +99,16 @@ protected function driverWrite(CacheItemInterface $item)
9999
VALUES (:cache_uuid, :cache_id, :cache_data, :cache_creation_date, :cache_expiration_date, :cache_length);
100100
', self::CASSANDRA_KEY_SPACE, self::CASSANDRA_TABLE);
101101

102-
$result = $this->instance->execute(new Cassandra\SimpleStatement($query), $options);
103-
/**
104-
* There's no real way atm
105-
* to know if the item has
106-
* been really upserted
107-
*/
108-
return $result instanceof Cassandra\Rows;
102+
$result = $this->instance->execute(new Cassandra\SimpleStatement($query), $options);
103+
/**
104+
* There's no real way atm
105+
* to know if the item has
106+
* been really upserted
107+
*/
108+
return $result instanceof Cassandra\Rows;
109+
}catch(\Cassandra\Exception\InvalidArgumentException $e){
110+
throw new phpFastCacheInvalidArgumentException($e, 0, $e);
111+
}
109112
} else {
110113
throw new phpFastCacheInvalidArgumentException('Cross-Driver type confusion detected');
111114
}

0 commit comments

Comments
 (0)