From 171b01ba9d4c53ce4517861738a91c4631828614 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Mon, 19 Jun 2023 14:02:18 +0200 Subject: [PATCH] Fix PHPStan error, update variable names --- src/Database/Concerns/DealsWithModels.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Database/Concerns/DealsWithModels.php b/src/Database/Concerns/DealsWithModels.php index db23ba33..bc99efa8 100644 --- a/src/Database/Concerns/DealsWithModels.php +++ b/src/Database/Concerns/DealsWithModels.php @@ -27,15 +27,15 @@ trait DealsWithModels return array_filter(array_map(function (SplFileInfo $file) { $fileContents = str($file->getContents()); - $class = $fileContents->after('class ')->before("\n")->explode(' ')->first(); + $className = $fileContents->after('class ')->before("\n")->explode(' ')->first(); if ($fileContents->contains('namespace ')) { - $class = $fileContents->after('namespace ')->before(';')->toString() . '\\' . $class; - $reflection = new ReflectionClass($class); + /** @var class-string $fullClassName */ + $fullClassName = $fileContents->after('namespace ')->before(';')->toString() . '\\' . $className; // Skip non-instantiable classes – we only care about models, and those are instantiable - if ($reflection->getConstructor()?->getNumberOfRequiredParameters() === 0) { - $object = new $class; + if ((new ReflectionClass($fullClassName))->getConstructor()?->getNumberOfRequiredParameters() === 0) { + $object = new $className; if ($object instanceof Model) { return $object;