Skip to content

Commit a56138b

Browse files
authored
Refactor attribute retrieval in DataModel (#51)
Simplify the process of fetching the Describe attribute by using the getAttributes method with a specific argument. This change improves code readability and reduces unnecessary filtering logic.
1 parent 2e9424b commit a56138b

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/DataModel.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,8 @@ public static function from(array|object|null|string $context = [], mixed $insta
167167

168168
$ReflectionClass = new ReflectionClass($self);
169169
/** Get Describe Attribute on class. */
170-
/** @var ReflectionAttribute $ClassAttribute */
171-
$ClassAttribute = current(
172-
array_filter(
173-
$ReflectionClass->getAttributes(),
174-
static fn(ReflectionAttribute $ReflectionAttribute) => $ReflectionAttribute->getName() === Describe::class
175-
)
176-
);
170+
/** @var ReflectionAttribute|bool $ClassAttribute */
171+
$ClassAttribute = current($ReflectionClass->getAttributes(Describe::class));
177172
/** @var Describe|null $ClassDescribe */
178173
$ClassDescribe = $ClassAttribute ? $ClassAttribute->newInstance() : null;
179174
$ClassDescribeArguments = $ClassAttribute ? $ClassAttribute->getArguments() : null;

0 commit comments

Comments
 (0)