@@ -7,28 +7,47 @@ class InMemoryStore implements MessageStore
77{
88 public array $ data = [];
99
10- public function store (string $ key , array $ value ): void { $ this ->data [$ key ] = $ value ; }
11- public function retrieve (string $ key ): ?array { return $ this ->data [$ key ] ?? null ; }
12- public function keys (?int $ since = null ): iterable {
10+ public function store (string $ key , array $ value ): void
11+ {
12+ $ this ->data [$ key ] = $ value ;
13+ }
14+
15+ public function retrieve (string $ key ): ?array
16+ {
17+ return $ this ->data [$ key ] ?? null ;
18+ }
19+
20+ public function keys (?int $ since = null ): iterable
21+ {
1322 foreach (array_keys ($ this ->data ) as $ k ) {
1423 if ($ since ) {
1524 $ ts = $ this ->data [$ k ]['timestamp ' ] ?? 0 ;
16- if ($ ts < $ since ) { continue ; }
25+ if ($ ts < $ since ) {
26+ continue ;
27+ }
1728 }
1829 yield $ k ;
1930 }
2031 }
21- public function delete (string $ key ): void { unset($ this ->data [$ key ]); }
22- public function purgeOlderThan (int $ seconds ): void {
32+
33+ public function delete (string $ key ): void
34+ {
35+ unset($ this ->data [$ key ]);
36+ }
37+
38+ public function purgeOlderThan (int $ seconds ): void
39+ {
2340 $ cut = time () - $ seconds ;
2441 foreach ($ this ->data as $ k => $ v ) {
25- if (($ v ['timestamp ' ] ?? 0 ) < $ cut ) unset($ this ->data [$ k ]);
42+ if (($ v ['timestamp ' ] ?? 0 ) < $ cut ) {
43+ unset($ this ->data [$ k ]);
44+ }
2645 }
2746 }
2847}
2948
3049it ('stores raw message with timestamp and returns a key ' , function () {
31- $ store = new InMemoryStore () ;
50+ $ store = new InMemoryStore ;
3251 $ svc = new CaptureService ($ store );
3352
3453 $ key = $ svc ->storeRaw ("Subject: Hi \r\n\r\nBody " );
0 commit comments