Skip to content

Commit e990adb

Browse files
committed
update: add error checking for a 0 key in numeric morph map
1 parent 0c0b371 commit e990adb

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/Logger.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use Illuminate\Database\Eloquent\Model;
77
use Illuminate\Support\Facades\Request;
8+
use InvalidArgumentException;
89
use Sourcetoad\Logger\Enums\ActivityType;
910
use Sourcetoad\Logger\Enums\HttpVerb;
1011
use Sourcetoad\Logger\Models\AuditActivity;
@@ -181,11 +182,19 @@ public static function getNumericMorphMap(Model $model): int
181182
$morphableTypeId = array_search($fcqn, $morphMap, true);
182183
}
183184

184-
if (is_numeric($morphableTypeId)) {
185-
return $morphableTypeId;
185+
if (!is_numeric($morphableTypeId)) {
186+
throw new InvalidArgumentException(
187+
sprintf('%s has no numeric model map. Check `morphs` in Logger.', get_class($model)),
188+
);
186189
}
187190

188-
throw new \InvalidArgumentException(get_class($model) . " has no numeric model map. Check `morphs` in Logger.");
191+
if ($morphableTypeId === 0) {
192+
throw new InvalidArgumentException(
193+
sprintf('0 is not a valid morph map key for %s. Check `morphs` in Logger.', get_class($model)),
194+
);
195+
}
196+
197+
return $morphableTypeId;
189198
}
190199

191200
private function getHttpVerb(string $verb): int

0 commit comments

Comments
 (0)