Skip to content

Commit fb4231b

Browse files
nikajorjikagithub-actions[bot]
authored andcommitted
Fix styling
1 parent 0c33245 commit fb4231b

File tree

12 files changed

+62
-41
lines changed

12 files changed

+62
-41
lines changed

config/inbox.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
return [
34
'store' => [
45
'driver' => env('INBOX_STORE_DRIVER', 'file'),

src/CaptureService.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,18 @@
66

77
class CaptureService
88
{
9-
public function __construct(protected MessageStore $storage)
10-
{
11-
}
9+
public function __construct(protected MessageStore $storage) {}
1210

1311
/**
1412
* Persist the raw message and metadata.
1513
*/
1614
public function storeRaw(string $raw): string
1715
{
18-
$key = 'email_' . md5($raw) . '_' . microtime(true);
16+
$key = 'email_'.md5($raw).'_'.microtime(true);
1917

2018
$this->storage->store($key, [
2119
'timestamp' => time(),
22-
'raw' => $raw,
20+
'raw' => $raw,
2321
]);
2422

2523
return $key;

src/Contracts/MessageStore.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,20 @@ interface MessageStore
99
*
1010
* @param string $key Unique key (you generate it).
1111
* @param array $value Associative array payload; MUST include at least: ['raw' => string, 'timestamp' => int]
12-
*
13-
* @return void
1412
*/
1513
public function store(string $key, array $value): void;
1614

1715
/**
1816
* Retrieve a single payload by key.
1917
*
2018
* @param string $key Unique key to retrieve the payload.
21-
*
2219
* @return array|null Returns the payload array or null if not found.
2320
*/
2421
public function retrieve(string $key): ?array;
2522

2623
/**
2724
* Retrieve multiple payload keys optionally filtered by a UNIX timestamp (>= since).
2825
*
29-
* @param int|null $since
3026
*
3127
* @return iterable<string> Keys
3228
*/

src/InboxServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ public function configurePackage(Package $package): void
2121
public function registeringPackage(): void
2222
{
2323
$this->app->singleton(MessageStore::class, function () {
24-
return (new StoreManager())->create();
24+
return (new StoreManager)->create();
2525
});
2626
$this->app->singleton(CaptureService::class, function () {
2727
return new CaptureService(app(MessageStore::class));
2828
});
2929

30-
$this->app->singleton(InboxTransport::class, fn() => new InboxTransport(app(CaptureService::class)));
30+
$this->app->singleton(InboxTransport::class, fn () => new InboxTransport(app(CaptureService::class)));
3131

3232
// Register the mail driver
3333
$this->app->afterResolving(MailManager::class, function (MailManager $manager) {

src/Storage/FileStorage.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class FileStorage implements MessageStore
1111
public function __construct(?string $basePath = null)
1212
{
1313
$this->basePath = $basePath ?: storage_path('app/mail-inbox');
14-
if (!is_dir($this->basePath)) {
14+
if (! is_dir($this->basePath)) {
1515
@mkdir($this->basePath, 0775, true);
1616
}
1717
}
@@ -27,7 +27,7 @@ public function store(string $key, array $value): void
2727
public function retrieve(string $key): ?array
2828
{
2929
$path = $this->pathFor($key);
30-
if (!is_file($path)) {
30+
if (! is_file($path)) {
3131
return null;
3232
}
3333

@@ -39,7 +39,7 @@ public function retrieve(string $key): ?array
3939

4040
public function keys(?int $since = null): iterable
4141
{
42-
if (!is_dir($this->basePath)) {
42+
if (! is_dir($this->basePath)) {
4343
return [];
4444
}
4545

@@ -49,7 +49,7 @@ public function keys(?int $since = null): iterable
4949

5050
if ($since) {
5151
$payload = $this->retrieve($key);
52-
if (!$payload || ($payload['timestamp'] ?? 0) < $since) {
52+
if (! $payload || ($payload['timestamp'] ?? 0) < $since) {
5353
continue;
5454
}
5555
}
@@ -72,7 +72,7 @@ public function purgeOlderThan(int $seconds): void
7272

7373
foreach ($this->keys() as $key) {
7474
$payload = $this->retrieve($key);
75-
if (!$payload) {
75+
if (! $payload) {
7676
continue;
7777
}
7878
if (($payload['timestamp'] ?? 0) < $cut) {

src/Transport/InboxTransport.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
class InboxTransport implements TransportInterface
1212
{
13-
public function __construct(protected CaptureService $mailbox)
14-
{
15-
}
13+
public function __construct(protected CaptureService $mailbox) {}
1614

1715
public function __toString(): string
1816
{

tests/Feature/MailerRegistrationTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@ public function build()
1616
$captured = (object) ['raw' => null];
1717

1818
$this->app->singleton(CaptureService::class, function () use ($captured) {
19-
return new class($captured) extends CaptureService {
19+
return new class($captured) extends CaptureService
20+
{
2021
public function __construct(private object $captured) {}
22+
2123
public function storeRaw(string $raw): string
2224
{
2325
$this->captured->raw = $raw;
26+
2427
return 'k';
2528
}
2629
};
2730
});
2831

29-
Mail::to('[email protected]')->send(new TestMailable());
32+
Mail::to('[email protected]')->send(new TestMailable);
3033

3134
expect($captured->raw)->not->toBeNull()
3235
->and($captured->raw)->toContain('Hello');

tests/TestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ protected function setUp(): void
1313
parent::setUp();
1414

1515
Factory::guessFactoryNamesUsing(
16-
fn(string $modelName
16+
fn (string $modelName
1717
) => 'Redberry\\MailboxForLaravel\\Database\\Factories\\'.class_basename($modelName).'Factory'
1818
);
1919
}
@@ -31,6 +31,6 @@ public function getEnvironmentSetUp($app)
3131

3232
$app['config']->set('mail.mailers.inbox', ['transport' => 'inbox']);
3333
$app['config']->set('mail.default', 'inbox');
34-
34+
3535
}
3636
}

tests/Unit/CaptureServiceTest.php

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3049
it('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");

tests/Unit/FileStorageTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
use Redberry\MailboxForLaravel\Storage\FileStorage;
44

55
beforeEach(function () {
6-
$this->basePath = sys_get_temp_dir() . '/inbox-fs-' . uniqid();
6+
$this->basePath = sys_get_temp_dir().'/inbox-fs-'.uniqid();
77
@mkdir($this->basePath, 0777, true);
88
$this->fs = new FileStorage($this->basePath);
99
});
1010

1111
afterEach(function () {
1212
if (is_dir($this->basePath)) {
13-
$files = glob($this->basePath . '/*');
14-
if ($files) { foreach ($files as $f) { @unlink($f); } }
13+
$files = glob($this->basePath.'/*');
14+
if ($files) {
15+
foreach ($files as $f) {
16+
@unlink($f);
17+
}
18+
}
1519
@rmdir($this->basePath);
1620
}
1721
});

0 commit comments

Comments
 (0)