Skip to content

Commit 9b259e2

Browse files
committed
Use class name notation instead of strings for FriendlyException attribute
- Remove unnecessary try/catch blocks as suggested in PR review
1 parent c08cf44 commit 9b259e2

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

src/Renderer/HtmlRenderer.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -507,18 +507,14 @@ public function getThrowableName(Throwable $throwable): string
507507
$name = $throwable->getName() . ' (' . $name . ')';
508508
} else {
509509
// Check if the exception class has FriendlyException attribute
510-
try {
511-
$reflectionClass = new ReflectionClass($throwable);
512-
if (class_exists('Yiisoft\FriendlyException\Attribute\FriendlyException')) {
513-
$attributes = $reflectionClass->getAttributes('Yiisoft\FriendlyException\Attribute\FriendlyException');
514-
515-
if (!empty($attributes)) {
516-
$friendlyExceptionAttribute = $attributes[0]->newInstance();
517-
$name = $friendlyExceptionAttribute->name . ' (' . $name . ')';
518-
}
510+
$reflectionClass = new ReflectionClass($throwable);
511+
if (class_exists(\Yiisoft\FriendlyException\Attribute\FriendlyException::class)) {
512+
$attributes = $reflectionClass->getAttributes(\Yiisoft\FriendlyException\Attribute\FriendlyException::class);
513+
514+
if (!empty($attributes)) {
515+
$friendlyExceptionAttribute = $attributes[0]->newInstance();
516+
$name = $friendlyExceptionAttribute->name . ' (' . $name . ')';
519517
}
520-
} catch (\Throwable $e) {
521-
// Ignore exception and keep default name
522518
}
523519
}
524520

templates/development.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
$solution = $isFriendlyException ? $throwable->getSolution() : null;
2828

2929
// Check if the exception class has FriendlyException attribute
30-
if ($solution === null && class_exists('Yiisoft\FriendlyException\Attribute\FriendlyException')) {
30+
if ($solution === null && class_exists(\Yiisoft\FriendlyException\Attribute\FriendlyException::class)) {
3131
try {
3232
$reflectionClass = new ReflectionClass($throwable);
33-
$attributes = $reflectionClass->getAttributes('Yiisoft\FriendlyException\Attribute\FriendlyException');
33+
$attributes = $reflectionClass->getAttributes(\Yiisoft\FriendlyException\Attribute\FriendlyException::class);
3434

3535
if (!empty($attributes)) {
3636
$friendlyExceptionAttribute = $attributes[0]->newInstance();
@@ -111,10 +111,10 @@
111111
// Check if the exception class has FriendlyException attribute
112112
$hasFriendlyNameFromAttribute = false;
113113

114-
if (class_exists('Yiisoft\FriendlyException\Attribute\FriendlyException')) {
114+
if (class_exists(\Yiisoft\FriendlyException\Attribute\FriendlyException::class)) {
115115
try {
116116
$reflectionClass = new ReflectionClass($throwable);
117-
$attributes = $reflectionClass->getAttributes('Yiisoft\FriendlyException\Attribute\FriendlyException');
117+
$attributes = $reflectionClass->getAttributes(\Yiisoft\FriendlyException\Attribute\FriendlyException::class);
118118

119119
if (!empty($attributes)) {
120120
$friendlyExceptionAttribute = $attributes[0]->newInstance();

0 commit comments

Comments
 (0)