Skip to content

Commit 987ccf7

Browse files
committed
refactor(collectors): Remove PhpInfoCollector and update ApplicationCollector
- Removed PhpInfoCollector as it is no longer needed - Added PHP version and memory usage in ApplicationCollector - Ensured relevant information is collected for improved performance
1 parent c73196c commit 987ccf7

21 files changed

+23
-97
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"pestphp/pest": "^1.23 || ^2.0 || ^3.0",
110110
"pestphp/pest-plugin-faker": "^1.0 || ^2.0 || ^3.0",
111111
"pestphp/pest-plugin-laravel": "^1.4 || ^2.0 || ^3.0",
112-
"php-mock/php-mock-phpunit": "^2.12",
112+
"php-mock/php-mock-phpunit": "^2.13",
113113
"phpstan/extension-installer": "^1.4",
114114
"phpstan/phpstan": "^2.1",
115115
"phpstan/phpstan-deprecation-rules": "^2.0",

config/exception-notify.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Guanguans\LaravelExceptionNotify\Collectors\ExceptionBasicCollector;
1919
use Guanguans\LaravelExceptionNotify\Collectors\ExceptionContextCollector;
2020
use Guanguans\LaravelExceptionNotify\Collectors\ExceptionTraceCollector;
21-
use Guanguans\LaravelExceptionNotify\Collectors\PhpInfoCollector;
2221
use Guanguans\LaravelExceptionNotify\Collectors\RequestBasicCollector;
2322
use Guanguans\LaravelExceptionNotify\Collectors\RequestFileCollector;
2423
use Guanguans\LaravelExceptionNotify\Collectors\RequestHeaderCollector;
@@ -70,7 +69,6 @@
7069
*/
7170
'collectors' => [
7271
ApplicationCollector::class,
73-
// PhpInfoCollector::class,
7472
ChoreCollector::class,
7573
RequestBasicCollector::class,
7674
ExceptionBasicCollector::class,

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ parameters:
7070
- identifier: argument.type
7171
- identifier: binaryOp.invalid
7272
- identifier: cast.string
73+
- identifier: encapsedStringPart.nonString
7374
- identifier: method.nonObject
7475
- identifier: missingType.generics
7576
- identifier: missingType.iterableValue

src/Channels/AbstractChannel.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ public function __construct(protected Repository $configRepository)
5252
throw_if($validator->fails(), InvalidConfigurationException::fromValidator($validator));
5353
}
5454

55-
/**
56-
* @throws \Illuminate\Contracts\Container\BindingResolutionException
57-
*/
5855
public function report(\Throwable $throwable): void
5956
{
6057
$pendingDispatch = dispatch($this->makeJob($throwable));
@@ -94,9 +91,6 @@ private function getChannel(): string
9491
return $this->configRepository->get('__channel');
9592
}
9693

97-
/**
98-
* @throws \Illuminate\Contracts\Container\BindingResolutionException
99-
*/
10094
private function makeJob(\Throwable $throwable): ShouldQueue
10195
{
10296
return Utils::applyConfigurationToObject(
@@ -109,9 +103,6 @@ private function makeJob(\Throwable $throwable): ShouldQueue
109103
);
110104
}
111105

112-
/**
113-
* @throws \Illuminate\Contracts\Container\BindingResolutionException
114-
*/
115106
private function getContent(\Throwable $throwable): string
116107
{
117108
return (string) (new Pipeline(app()))

src/Channels/Channel.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,13 @@ public static function flush(): void
7979
self::$skipCallbacks = [];
8080
}
8181

82-
/**
83-
* @throws \Illuminate\Contracts\Container\BindingResolutionException
84-
*/
8582
public function shouldReport(\Throwable $throwable): bool
8683
{
8784
return !$this->shouldntReport($throwable);
8885
}
8986

9087
/**
9188
* @see \Illuminate\Foundation\Exceptions\Handler::shouldntReport()
92-
*
93-
* @throws \Illuminate\Contracts\Container\BindingResolutionException
9489
*/
9590
private function shouldntReport(\Throwable $throwable): bool
9691
{
@@ -113,8 +108,6 @@ private function shouldSkip(\Throwable $throwable): bool
113108
/**
114109
* @see \Illuminate\Cache\RateLimiting\Limit
115110
* @see RateLimiter::attempt()
116-
*
117-
* @throws \Illuminate\Contracts\Container\BindingResolutionException
118111
*/
119112
private function attempt(\Throwable $throwable): bool
120113
{

src/Channels/MailChannel.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
*/
2828
class MailChannel extends AbstractChannel
2929
{
30-
/**
31-
* @throws \Illuminate\Contracts\Container\BindingResolutionException
32-
*/
3330
public function reportContent(string $content): ?SentMessage
3431
{
3532
return Mail::mailer($this->configRepository->get('mailer'))->send($this->makeMail($content));
@@ -43,9 +40,6 @@ protected function rules(): array
4340
] + parent::rules();
4441
}
4542

46-
/**
47-
* @throws \Illuminate\Contracts\Container\BindingResolutionException
48-
*/
4943
private function makeMail(string $content): Mailable
5044
{
5145
return Utils::applyConfigurationToObject(

src/Channels/NotifyChannel.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Guanguans\Notify\Foundation\Contracts\Authenticator;
1818
use Guanguans\Notify\Foundation\Contracts\Client;
1919
use Guanguans\Notify\Foundation\Message;
20-
use Illuminate\Contracts\Container\BindingResolutionException;
2120
use Psr\Http\Message\ResponseInterface;
2221
use function Guanguans\LaravelExceptionNotify\Support\make;
2322

@@ -28,9 +27,6 @@
2827
*/
2928
class NotifyChannel extends AbstractChannel
3029
{
31-
/**
32-
* @throws \Illuminate\Contracts\Container\BindingResolutionException
33-
*/
3430
public function reportContent(string $content): ResponseInterface
3531
{
3632
return $this->makeClient()->send($this->makeMessage($content));
@@ -48,9 +44,6 @@ protected function rules(): array
4844
] + parent::rules();
4945
}
5046

51-
/**
52-
* @throws BindingResolutionException
53-
*/
5447
private function makeClient(): Client
5548
{
5649
return Utils::applyConfigurationToObject(
@@ -61,9 +54,6 @@ private function makeClient(): Client
6154
);
6255
}
6356

64-
/**
65-
* @throws \Illuminate\Contracts\Container\BindingResolutionException
66-
*/
6757
private function makeAuthenticator(): Authenticator
6858
{
6959
return Utils::applyConfigurationToObject(
@@ -72,9 +62,6 @@ private function makeAuthenticator(): Authenticator
7262
);
7363
}
7464

75-
/**
76-
* @throws BindingResolutionException
77-
*/
7865
private function makeMessage(string $content): Message
7966
{
8067
return Utils::applyConfigurationToObject(

src/Collectors/ApplicationCollector.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use Illuminate\Container\Container;
1717
use Illuminate\Support\Carbon;
18+
use function Guanguans\LaravelExceptionNotify\Support\human_bytes;
1819

1920
class ApplicationCollector extends AbstractCollector
2021
{
@@ -29,10 +30,12 @@ public function collect(): array
2930
'time' => Carbon::now()->format('Y-m-d H:i:s'),
3031
'name' => config('app.name'),
3132
'version' => $this->container->version(),
33+
'php version' => \PHP_VERSION,
3234
'environment' => $this->container->environment(),
3335
'debug' => $this->container->hasDebugModeEnabled(),
3436
'locale' => $this->container->getLocale(),
3537
'in console' => $this->container->runningInConsole(),
38+
'memory' => human_bytes(memory_get_peak_usage(true)),
3639
];
3740
}
3841
}

src/Collectors/ExceptionTraceCollector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public function __construct(?array $except = null)
2424

2525
public function collect(): array
2626
{
27-
return collect(explode(\PHP_EOL, $this->exception->getTraceAsString()))
27+
return str($this->exception->getTraceAsString())
28+
->explode(\PHP_EOL)
2829
->reject(fn (string $trace): bool => str($trace)->contains($this->except))
2930
->map(static fn (string $trace): string => (string) str($trace)->replaceFirst(base_path(), ''))
3031
->all();

src/Collectors/PhpInfoCollector.php

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

src/Commands/Concerns/Configureable.php

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

3-
/** @noinspection PhpUndefinedClassInspection */
43
/** @noinspection MethodVisibilityInspection */
54

65
declare(strict_types=1);

src/Commands/TestCommand.php

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

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

src/ExceptionNotifyManager.php

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

33
/** @noinspection PhpUnused */
4-
/** @noinspection PhpUnusedPrivateMethodInspection */
54

65
declare(strict_types=1);
76

@@ -22,7 +21,6 @@
2221
use Guanguans\LaravelExceptionNotify\Support\Traits\AggregationTrait;
2322
use Illuminate\Config\Repository;
2423
use Illuminate\Support\Manager;
25-
use Illuminate\Support\Str;
2624
use function Guanguans\LaravelExceptionNotify\Support\rescue;
2725

2826
/**
@@ -90,7 +88,7 @@ private function createOriginalDriver(string $driver): ChannelContract
9088
static fn (Repository $configRepository): mixed => $configRepository->set('__channel', $driver)
9189
);
9290

93-
$studlyName = Str::studly($configRepository->get('driver', $driver));
91+
$studlyName = str($configRepository->get('driver', $driver))->studly();
9492

9593
if (class_exists($class = "\\Guanguans\\LaravelExceptionNotify\\Channels\\{$studlyName}Channel")) {
9694
return new $class($configRepository);

src/ExceptionNotifyServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Guanguans\LaravelExceptionNotify\Facades\ExceptionNotify;
1818
use Illuminate\Contracts\Debug\ExceptionHandler;
1919
use Illuminate\Support\ServiceProvider;
20-
use Illuminate\Support\Str;
20+
use Illuminate\Support\Stringable;
2121

2222
class ExceptionNotifyServiceProvider extends ServiceProvider
2323
{
@@ -128,7 +128,7 @@ private function toAlias(string $class): string
128128
->start('\\'.class_basename(ExceptionNotify::class))
129129
->replaceFirst('\\', '')
130130
->explode('\\')
131-
->map(static fn (string $name): string => Str::snake($name, '-'))
131+
->map(static fn (string $name): Stringable => str($name)->snake('-'))
132132
->implode('.');
133133
}
134134
}

src/Pipes/AddChorePipe.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Guanguans\LaravelExceptionNotify\Support\Traits\WithPipeArgs;
1818
use Illuminate\Support\Arr;
1919
use Illuminate\Support\Collection;
20-
use Illuminate\Support\Str;
2120
use Illuminate\Support\Stringable;
2221

2322
class AddChorePipe
@@ -31,7 +30,7 @@ public function handle(Collection $collectors, \Closure $next, mixed $value, mix
3130
{
3231
return $next(collect(Arr::add(
3332
$collectors->all(),
34-
Str::start($key, ChoreCollector::fallbackName().'.'),
33+
str($key)->start(ChoreCollector::fallbackName().'.')->toString(),
3534
$value
3635
)));
3736
}

src/Support/ExceptionContext.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace Guanguans\LaravelExceptionNotify\Support;
1515

1616
use Illuminate\Support\Collection;
17-
use Illuminate\Support\Str;
1817

1918
/**
2019
* @see https://github.com/laravel/telescope/blob/4.x/src/ExceptionContext.php
@@ -62,7 +61,7 @@ public static function get(\Throwable $throwable, int $number = 5): array
6261
*/
6362
private static function getEval(\Throwable $throwable): ?array
6463
{
65-
return Str::contains($throwable->getFile(), $row = "eval()'d code") ? [$throwable->getLine() => $row] : null;
64+
return str($throwable->getFile())->contains($row = "eval()'d code") ? [$throwable->getLine() => $row] : null;
6665
}
6766

6867
private static function getFile(\Throwable $throwable, int $number = 5): array

src/Support/Rectors/ToInternalExceptionRector.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace Guanguans\LaravelExceptionNotify\Support\Rectors;
1515

16-
use Illuminate\Support\Str;
1716
use PhpParser\Node;
1817
use PhpParser\Node\Expr\New_;
1918
use PhpParser\Node\Name;
@@ -78,9 +77,9 @@ public function refactor(Node $node): ?Node
7877

7978
if (
8079
!$class instanceof Name
81-
|| Str::is($this->except, $class->toString())
8280
|| str_starts_with($class->toString(), 'Guanguans\\LaravelExceptionNotify\\Exceptions\\')
8381
|| !str_ends_with($class->toString(), 'Exception')
82+
|| str($class->toString())->is($this->except)
8483
) {
8584
return null;
8685
}

src/Support/helpers.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@
1919

2020
if (!\function_exists('Guanguans\LaravelExceptionNotify\Support\make')) {
2121
/**
22+
* @see https://github.com/laravel/framework/blob/12.x/src/Illuminate/Foundation/helpers.php
2223
* @see https://github.com/yiisoft/yii2/blob/master/framework/BaseYii.php
2324
*
24-
* @param array<string, mixed>|string $abstract
25+
* @template TClass of object
26+
*
27+
* @param array<string, mixed>|class-string<TClass>|string $name
2528
* @param array<string, mixed> $parameters
2629
*
27-
* @throws \Illuminate\Contracts\Container\BindingResolutionException
30+
* @return ($name is class-string<TClass> ? TClass : mixed)
2831
*/
29-
function make(array|string $abstract, array $parameters = []): mixed
32+
function make(array|string $name, array $parameters = []): mixed
3033
{
31-
if (\is_string($abstract)) {
32-
return resolve($abstract, $parameters);
34+
if (\is_string($name)) {
35+
return resolve($name, $parameters);
3336
}
3437

3538
foreach (
@@ -45,8 +48,8 @@ function make(array|string $abstract, array $parameters = []): mixed
4548
'name',
4649
] as $key
4750
) {
48-
if (isset($abstract[$key])) {
49-
return make($abstract[$key], $parameters + Arr::except($abstract, $key));
51+
if (isset($name[$key])) {
52+
return make($name[$key], $parameters + Arr::except($name, $key));
5053
}
5154
}
5255

tests/TestCase.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use Guanguans\LaravelExceptionNotify\Collectors\ExceptionBasicCollector;
2222
use Guanguans\LaravelExceptionNotify\Collectors\ExceptionContextCollector;
2323
use Guanguans\LaravelExceptionNotify\Collectors\ExceptionTraceCollector;
24-
use Guanguans\LaravelExceptionNotify\Collectors\PhpInfoCollector;
2524
use Guanguans\LaravelExceptionNotify\Collectors\RequestBasicCollector;
2625
use Guanguans\LaravelExceptionNotify\Collectors\RequestFileCollector;
2726
use Guanguans\LaravelExceptionNotify\Collectors\RequestHeaderCollector;
@@ -94,7 +93,6 @@ protected function defineEnvironment($app): void
9493
ExceptionBasicCollector::class,
9594
ExceptionContextCollector::class,
9695
ExceptionTraceCollector::class,
97-
PhpInfoCollector::class,
9896
RequestBasicCollector::class,
9997
RequestFileCollector::class,
10098
RequestHeaderCollector::class,

vendor-bin/composer-unused/composer.json

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

vendor-bin/larastan/composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
22
"require-dev": {
3-
"larastan/larastan": "^2.0"
43
}
54
}

0 commit comments

Comments
 (0)