55use Lkrms \Store \Concept \SqliteStore ;
66use DateTimeInterface ;
77use InvalidArgumentException ;
8+ use LogicException ;
89
910/**
1011 * A SQLite-backed key-value store
@@ -61,10 +62,12 @@ public function set(string $key, $value, $expires = null)
6162 } elseif (!$ expires ) {
6263 $ expires = null ;
6364 } elseif (!is_int ($ expires ) || $ expires < 0 ) {
65+ // @codeCoverageIgnoreStart
6466 throw new InvalidArgumentException (sprintf (
6567 'Invalid $expires: %s ' ,
6668 $ expires
6769 ));
70+ // @codeCoverageIgnoreEnd
6871 } elseif ($ expires < 1625061600 ) {
6972 // Assume values less than the timestamp of 1 Jul 2021 00:00:00 AEST
7073 // are lifetimes in seconds
@@ -274,7 +277,11 @@ public function flush()
274277 */
275278 public function maybeGet (string $ key , callable $ callback , $ expires = null )
276279 {
277- $ store = $ this ->asOfNow ();
280+ $ store =
281+ $ this ->Now === null
282+ ? $ this ->asOfNow ()
283+ : $ this ;
284+
278285 if ($ store ->has ($ key )) {
279286 return $ store ->get ($ key );
280287 }
@@ -299,8 +306,12 @@ public function maybeGet(string $key, callable $callback, $expires = null)
299306 */
300307 public function asOfNow (?int $ now = null )
301308 {
302- if ($ now === null && $ this ->Now !== null ) {
303- return $ this ;
309+ if ($ this ->Now !== null ) {
310+ // @codeCoverageIgnoreStart
311+ throw new LogicException (
312+ sprintf ('Calls to %s cannot be nested ' , __METHOD__ )
313+ );
314+ // @codeCoverageIgnoreEnd
304315 }
305316
306317 $ clone = clone $ this ;
0 commit comments