Skip to content

Commit c73196c

Browse files
committed
refactor(baselines): Remove obsolete baseline error files
- Deleted several unused baseline error files to streamline the project - Updated loader configuration to reflect the removal and reduce total errors - Improved code readability by casting to array explicitly
1 parent 2a93e60 commit c73196c

21 files changed

+48
-89
lines changed

baselines/arrayUnpacking.nonIterable.neon

Lines changed: 0 additions & 8 deletions
This file was deleted.

baselines/callable.nonCallable.neon

Lines changed: 0 additions & 8 deletions
This file was deleted.

baselines/loader.neon

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
# total 8 errors
1+
# total 2 errors
22
includes:
3-
- arrayUnpacking.nonIterable.neon
4-
- callable.nonCallable.neon
53
- disallowed.function.neon
6-
- method.notFound.neon
7-
- nullCoalesce.variable.neon
8-
- offsetAccess.nonArray.neon

baselines/method.notFound.neon

Lines changed: 0 additions & 8 deletions
This file was deleted.

baselines/nullCoalesce.variable.neon

Lines changed: 0 additions & 8 deletions
This file was deleted.

baselines/offsetAccess.nonArray.neon

Lines changed: 0 additions & 8 deletions
This file was deleted.

config/exception-notify.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
/** @noinspection PhpUnusedAliasInspection */
4+
35
declare(strict_types=1);
46

57
/**
@@ -63,11 +65,6 @@
6365
'queue' => env('EXCEPTION_NOTIFY_JOB_QUEUE'),
6466
],
6567

66-
/**
67-
* The title of report exception.
68-
*/
69-
'title' => env('EXCEPTION_NOTIFY_TITLE', \sprintf('The %s application exception report', config('app.name'))),
70-
7168
/**
7269
* The list of collector that report exception.
7370
*/
@@ -86,6 +83,11 @@
8683
// RequestFileCollector::class,
8784
],
8885

86+
/**
87+
* The title of report exception.
88+
*/
89+
'title' => env('EXCEPTION_NOTIFY_TITLE', \sprintf('The %s application exception report', config('app.name'))),
90+
8991
/**
9092
* The default channel of report exception.
9193
*/

rector.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ static function (array $carry, mixed $value, string $name) use ($class): array {
218218
->withConfiguredRule(
219219
RenameFunctionRector::class,
220220
[
221+
// 'app' => 'resolve',
221222
'faker' => 'fake',
222223
'Guanguans\Notify\Foundation\Support\rescue' => 'Guanguans\LaravelExceptionNotify\Support\rescue',
223224
'Pest\Faker\fake' => 'fake',

src/Channels/AbstractChannel.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,18 @@ private function getContent(\Throwable $throwable): string
120120
->then(static fn (Collection $collectors): Stringable => str(json_pretty_encode($collectors->jsonSerialize())));
121121
}
122122

123-
/**
124-
* @throws \Illuminate\Contracts\Container\BindingResolutionException
125-
*/
126123
private function getCollectors(\Throwable $throwable): Collection
127124
{
128125
return collect([
129-
...config('exception-notify.collectors', []),
130-
...$this->configRepository->get('collectors', []),
126+
...(array) config('exception-notify.collectors'),
127+
...(array) $this->configRepository->get('collectors'),
131128
])->mapWithKeys(static function (array|string $parameters, int|string $class) use ($throwable): array {
132129
if (!\is_array($parameters)) {
133130
[$parameters, $class] = [(array) $class, $parameters];
134131
}
135132

136133
/** @var CollectorContract $collectorContract */
137-
$collectorContract = app()->make($class, $parameters);
134+
$collectorContract = resolve($class, $parameters);
138135
$collectorContract instanceof ExceptionAwareContract and $collectorContract->setException($throwable);
139136

140137
return [$collectorContract->name() => $collectorContract->collect()];
@@ -143,6 +140,6 @@ private function getCollectors(\Throwable $throwable): Collection
143140

144141
private function getPipes(): array
145142
{
146-
return collect($this->configRepository->get('pipes', []))->prepend(FixPrettyJsonPipe::class)->all();
143+
return collect($this->configRepository->get('pipes'))->prepend(FixPrettyJsonPipe::class)->all();
147144
}
148145
}

src/Channels/Channel.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ public function __construct(
4444
public function report(\Throwable $throwable): void
4545
{
4646
rescue(function () use ($throwable): void {
47-
if ($this->shouldntReport($throwable)) {
48-
return;
49-
}
50-
51-
$this->channelContract->report($throwable);
47+
$this->shouldReport($throwable) and $this->channelContract->report($throwable);
5248
});
5349
}
5450

@@ -122,17 +118,20 @@ private function shouldSkip(\Throwable $throwable): bool
122118
*/
123119
private function attempt(\Throwable $throwable): bool
124120
{
125-
return Utils::applyConfigurationToObject(
126-
make($configuration = config('exception-notify.rate_limiter') + [
127-
'class' => RateLimiter::class,
128-
'cache' => Cache::store(config('exception-notify.rate_limiter.cache_store')),
129-
]),
130-
$configuration
131-
)->attempt(
132-
$this->fingerprintFor($throwable),
133-
config('exception-notify.rate_limiter.max_attempts'),
134-
static fn (): bool => true,
135-
config('exception-notify.rate_limiter.decay_seconds')
121+
return value(
122+
fn (RateLimiter $rateLimiter): bool => $rateLimiter->attempt(
123+
$this->fingerprintFor($throwable),
124+
config('exception-notify.rate_limiter.max_attempts'),
125+
static fn (): bool => true,
126+
config('exception-notify.rate_limiter.decay_seconds')
127+
),
128+
Utils::applyConfigurationToObject(
129+
make($configuration = config('exception-notify.rate_limiter') + [
130+
'class' => RateLimiter::class,
131+
'cache' => Cache::store(config('exception-notify.rate_limiter.cache_store')),
132+
]),
133+
$configuration
134+
),
136135
);
137136
}
138137

src/Channels/NotifyChannel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
use function Guanguans\LaravelExceptionNotify\Support\make;
2323

2424
/**
25+
* @see \Guanguans\Notify\Foundation\Authenticators
2526
* @see \Guanguans\Notify\Foundation\Client
2627
* @see \Guanguans\Notify\Foundation\Message
27-
* @see \Guanguans\Notify\Foundation\Authenticators
2828
*/
2929
class NotifyChannel extends AbstractChannel
3030
{

src/Commands/Concerns/Configureable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
4949
->mapWithKeys(static function (string $config): array {
5050
\assert(str_contains($config, '='), "The configureable option [$config] must be formatted as key=value.");
5151

52-
[$key, $value] = str($config)->explode('=', 2)->all();
52+
[$key, $value] = explode('=', $config, 2);
5353

5454
return [$key => $value];
5555
})

src/Commands/TestCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class TestCommand extends Command
3737
/** @noinspection ClassOverridesFieldOfSuperClassInspection */
3838
protected $description = 'Testing for exception-notify';
3939

40+
/**
41+
* @throws \Illuminate\Contracts\Container\BindingResolutionException
42+
*/
4043
public function handle(ExceptionNotifyManager $exceptionNotifyManager): int
4144
{
4245
$this->output->info('Testing for exception-notify start.');

src/Pipes/LimitLengthPipe.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class LimitLengthPipe
2222
use WithPipeArgs;
2323

2424
/**
25+
* @noinspection RedundantDocCommentTagInspection
26+
*
2527
* @param \Closure(\Illuminate\Support\Collection): \Illuminate\Support\Stringable $next
2628
*/
2729
public function handle(Collection $collectors, \Closure $next, int $length, float $percentage = 0.9): Stringable

src/Support/JsonFixer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
/** @noinspection PhpClassHasTooManyDeclaredMembersInspection */
4+
35
declare(strict_types=1);
46

57
/**

src/Support/Rectors/HydratePipeFuncCallToStaticCallRector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
/** @noinspection PhpClassNamingConventionInspection */
4+
35
declare(strict_types=1);
46

57
/**

src/Support/Utils.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public static function applyConfigurationToObject(object $object, array $configu
8585
}
8686

8787
if (!\is_callable($extender)) {
88+
/** @var callable $extender */
8889
$extender = make($extender);
8990
}
9091

src/Support/helpers.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function make(array|string $abstract, array $parameters = []): mixed
3333
}
3434

3535
foreach (
36-
$keys ??= [
36+
$keys = [
3737
'__abstract',
3838
'__class',
3939
'__name',
@@ -112,11 +112,6 @@ function json_pretty_encode(mixed $value, int $options = 0, int $depth = 512): s
112112

113113
if (!\function_exists('Guanguans\LaravelExceptionNotify\Support\human_bytes')) {
114114
/**
115-
* Convert bytes to human readable format.
116-
*
117-
* @param int $bytes the amount of bytes to convert to human readable format
118-
* @param int $decimals the number of decimals to use in the resulting string
119-
*
120115
* @see https://stackoverflow.com/a/23888858/1580028
121116
*/
122117
function human_bytes(int $bytes, int $decimals = 2): string

tests/Channels/ChannelTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
it('can attempt Exception', function (): void {
4848
config()->set('exception-notify.rate_limiter.max_attempts', 3);
4949
expect(fn () => $this->attempt(new RuntimeException(microtime())))
50-
->call($logChannel = app(ExceptionNotifyManager::class)->channel('log'))->toBeTrue()
50+
->call($logChannel = resolve(ExceptionNotifyManager::class)->channel('log'))->toBeTrue()
5151
->call($logChannel)->toBeTrue()
5252
->call($logChannel)->toBeTrue()
5353
->call($logChannel)->toBeFalse();

tests/Collectors/CollectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
->once()
2828
->andReturnNull();
2929

30-
expect(app(RequestBasicCollector::class))
30+
expect(resolve(RequestBasicCollector::class))
3131
->collect()->toBeArray();
3232
})->group(__DIR__, __FILE__);

tests/ExceptionNotifyManagerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424

2525
it('can call', function (): void {
2626
ExceptionNotifyManager::macro('foo', fn ($param) => $param);
27-
expect(app(ExceptionNotifyManager::class))
27+
expect(resolve(ExceptionNotifyManager::class))
2828
->foo('foo')->toBe('foo');
2929
})->group(__DIR__, __FILE__);
3030

3131
it('can return Channel', function (): void {
32-
expect(app(ExceptionNotifyManager::class)->channel('log'))
32+
expect(resolve(ExceptionNotifyManager::class)->channel('log'))
3333
->toBeInstanceOf(Channel::class);
3434
})->group(__DIR__, __FILE__);
3535

@@ -46,11 +46,11 @@
4646
})->group(__DIR__, __FILE__);
4747

4848
it('will throw `InvalidArgumentException`', function (): void {
49-
app(ExceptionNotifyManager::class)->driver('foo');
49+
resolve(ExceptionNotifyManager::class)->driver('foo');
5050
})->group(__DIR__, __FILE__)->throws(InvalidArgumentException::class);
5151

5252
it('can create custom driver', function (): void {
53-
app(ExceptionNotifyManager::class)->extend('foo', static fn (): ChannelContract => new class implements ChannelContract {
53+
resolve(ExceptionNotifyManager::class)->extend('foo', static fn (): ChannelContract => new class implements ChannelContract {
5454
public function report(Throwable $throwable): void {}
5555

5656
public function reportContent(string $content): mixed
@@ -59,5 +59,5 @@ public function reportContent(string $content): mixed
5959
}
6060
});
6161

62-
expect(app(ExceptionNotifyManager::class))->driver('foo')->toBeInstanceOf(ChannelContract::class);
62+
expect(resolve(ExceptionNotifyManager::class))->driver('foo')->toBeInstanceOf(ChannelContract::class);
6363
})->group(__DIR__, __FILE__);

0 commit comments

Comments
 (0)