Skip to content

Commit d7aea8b

Browse files
committed
fix(ExceptionNotifyServiceProvider): Improve about command logic
- Refactor the way composer.json data is retrieved for the about command - Utilize `Collection` methods for safer handling of data - Ensure proper checks for file existence and class availability - Update test to assert command execution correctly
1 parent da847c8 commit d7aea8b

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# total 1 error
2+
3+
parameters:
4+
ignoreErrors:
5+
-
6+
message: '#^Call to function is_string\(\) with \*NEVER\* will always evaluate to true\.$#'
7+
count: 1
8+
path: ../src/ExceptionNotifyServiceProvider.php

baselines/loader.neon

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
# total 2 errors
1+
# total 3 errors
22
includes:
33
- disallowed.function.neon
4+
- function.alreadyNarrowedType.neon

src/ExceptionNotifyServiceProvider.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Illuminate\Contracts\Debug\ExceptionHandler;
2020
use Illuminate\Foundation\Console\AboutCommand;
2121
use Illuminate\Support\Arr;
22+
use Illuminate\Support\Collection;
2223
use Illuminate\Support\Facades\File;
2324
use Illuminate\Support\ServiceProvider;
2425
use Illuminate\Support\Stringable;
@@ -118,10 +119,19 @@ private function addSectionToAboutCommand(): void
118119
AboutCommand::add('Laravel Exception Notify', static function (): array {
119120
$package = 'guanguans/laravel-exception-notify';
120121

121-
return collect(
122-
json_decode(File::get(base_path("vendor/$package/composer.json")), true, 512, \JSON_THROW_ON_ERROR)
123-
+ Arr::get(InstalledVersions::getAllRawData(), "0.versions.$package", [])
124-
)
122+
return collect()
123+
->when(
124+
is_file($path = base_path("vendor/$package/composer.json")),
125+
static fn (Collection $data): Collection => $data->replace(
126+
json_decode(File::get($path), true, 512, \JSON_THROW_ON_ERROR)
127+
)
128+
)
129+
->when(
130+
class_exists(InstalledVersions::class),
131+
static fn (Collection $data): Collection => $data->replace(
132+
Arr::get(InstalledVersions::getAllRawData(), "0.versions.$package", [])
133+
)
134+
)
125135
->filter(static fn (mixed $value): bool => \is_string($value))
126136
->except([
127137
'$schema',

tests/ExceptionNotifyServiceProviderTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
*/
2020

2121
use Guanguans\LaravelExceptionNotify\ExceptionNotifyServiceProvider;
22-
use Illuminate\Contracts\Filesystem\FileNotFoundException;
2322
use function Pest\Laravel\artisan;
2423

2524
it('can add section to about command', function (): void {
26-
artisan('about');
27-
})->group(__DIR__, __FILE__)->throws(FileNotFoundException::class);
25+
artisan('about')->assertOk();
26+
})->group(__DIR__, __FILE__);
2827

2928
it('can get provides', function (): void {
3029
expect(new ExceptionNotifyServiceProvider(app()))

0 commit comments

Comments
 (0)