Skip to content

Commit dd725be

Browse files
committed
refactor(collector): Simplify naming and exception handling
- Remove the Naming and ExceptionAware traits - Implement name and fallbackName methods directly in AbstractCollector - Update exception handling in AbstractExceptionCollector - Streamline rescue function mappings in rector.php - Improve readability and maintainability of the code
1 parent 4adfffe commit dd725be

14 files changed

+46
-103
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,11 @@
225225
"@composer-validate",
226226
"@yaml-lint",
227227
"@md-lint",
228+
"@facade-lint",
229+
"@style-lint",
228230
"@composer-dependency-analyser",
229-
"@sk-check-conflicts",
230231
"@test",
232+
"@phpstan",
231233
"@rector-dry-run"
232234
],
233235
"class-leak": "@php ./vendor/bin/class-leak --ansi -v",

phpstan.neon

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,15 @@ parameters:
6868
message: 'use Pipe::with() instead'
6969
ignoreErrors:
7070
# - '#^Unable to resolve the template type T(Key|Value) in call to function collect$#'
71-
-
72-
identifier: argument.templateType
73-
-
74-
identifier: missingType.iterableValue
75-
-
76-
identifier: missingType.generics
77-
-
78-
identifier: return.void
79-
# -
80-
# identifier: new.static
81-
# -
82-
# identifier: logicalOr.resultUnused
83-
-
84-
identifier: trait.unused
85-
-
86-
identifier: method.nonObject
87-
-
88-
identifier: symplify.noDynamicName
71+
# - identifier: logicalOr.resultUnused
72+
# - identifier: new.static
73+
# - identifier: trait.unused
74+
- identifier: argument.templateType
75+
- identifier: method.nonObject
76+
- identifier: missingType.generics
77+
- identifier: missingType.iterableValue
78+
- identifier: return.void
79+
- identifier: symplify.noDynamicName
8980
-
9081
message: '#^Calling env\(\) is forbidden, use config\(\) instead\.$#'
9182
path: ./config/exception-notify.php

rector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,10 @@ static function (array $carry, mixed $value, string $name) use ($class): array {
223223
RenameFunctionRector::class,
224224
[
225225
// 'faker' => 'fake',
226-
'Guanguans\Notify\Foundation\Support\rescue' => 'Guanguans\LaravelExceptionNotify\Support\rescue',
226+
'Guanguans\LaravelExceptionNotify\Support\rescue' => 'rescue',
227+
'Guanguans\Notify\Foundation\Support\rescue' => 'rescue',
227228
'Pest\Faker\fake' => 'fake',
228229
'Pest\Faker\faker' => 'faker',
229-
'rescue' => 'Guanguans\LaravelExceptionNotify\Support\rescue',
230230
'test' => 'it',
231231
] + array_reduce(
232232
[

src/Collectors/AbstractCollector.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,19 @@
1313

1414
namespace Guanguans\LaravelExceptionNotify\Collectors;
1515

16-
use Guanguans\LaravelExceptionNotify\Collectors\Concerns\Naming;
1716
use Guanguans\LaravelExceptionNotify\Contracts\CollectorContract;
1817

1918
abstract class AbstractCollector implements CollectorContract
2019
{
21-
use Naming;
20+
public function name(): string
21+
{
22+
return static::fallbackName();
23+
}
24+
25+
public static function fallbackName(): string
26+
{
27+
return (string) str(class_basename(static::class))
28+
->beforeLast(str(class_basename(self::class))->replace('Abstract', ''))
29+
->snake(' ');
30+
}
2231
}

src/Collectors/AbstractExceptionCollector.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,17 @@
1313

1414
namespace Guanguans\LaravelExceptionNotify\Collectors;
1515

16-
use Guanguans\LaravelExceptionNotify\Collectors\Concerns\ExceptionAware;
1716
use Guanguans\LaravelExceptionNotify\Contracts\ExceptionAwareContract;
17+
use Symfony\Component\ErrorHandler\Exception\FlattenException;
1818

1919
abstract class AbstractExceptionCollector extends AbstractCollector implements ExceptionAwareContract
2020
{
21-
use ExceptionAware;
21+
protected \Throwable $exception;
22+
protected FlattenException $flattenException;
23+
24+
public function setException(\Throwable $throwable): void
25+
{
26+
$this->exception = $throwable;
27+
$this->flattenException = FlattenException::createFromThrowable($throwable);
28+
}
2229
}

src/Collectors/Concerns/ExceptionAware.php

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

src/Collectors/Concerns/Naming.php

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

src/Collectors/ExceptionBasicCollector.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ public function collect(): array
2626
'class' => $this->exception::class,
2727
'file' => $this->exception->getFile(),
2828
'line' => $this->exception->getLine(),
29-
// 'status_code' => $this->flattenException->getStatusCode(),
30-
// 'status_text' => $this->flattenException->getStatusText(),
31-
// 'headers' => $this->flattenException->getHeaders(),
3229
];
3330
}
3431
}

src/Commands/TestCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@
2828
class TestCommand extends Command
2929
{
3030
use Configureable;
31+
32+
/** @noinspection ClassOverridesFieldOfSuperClassInspection */
3133
protected $signature = <<<'SIGNATURE'
3234
exception-notify:test
3335
{--c|channel=* : Specify channel to test}
3436
{--j|job-connection=* : Specify job connection to test}
3537
SIGNATURE;
38+
39+
/** @noinspection ClassOverridesFieldOfSuperClassInspection */
3640
protected $description = 'Test for exception-notify';
3741

3842
public function handle(ExceptionNotifyManager $exceptionNotifyManager): int

src/ExceptionNotifyManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
/**
2828
* @property \Illuminate\Foundation\Application $container
2929
*
30-
* @method \Guanguans\LaravelExceptionNotify\Channels\Channel driver($driver = null)
30+
* @method \Guanguans\LaravelExceptionNotify\Channels\Channel driver(?string $driver = null)
3131
*
3232
* @mixin \Guanguans\LaravelExceptionNotify\Channels\Channel
3333
*/

0 commit comments

Comments
 (0)