Skip to content

Commit

Permalink
update: add error checking for a 0 key in numeric morph map
Browse files Browse the repository at this point in the history
  • Loading branch information
rbondoc96 committed Nov 20, 2024
1 parent 0c0b371 commit e990adb
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Request;
use InvalidArgumentException;
use Sourcetoad\Logger\Enums\ActivityType;
use Sourcetoad\Logger\Enums\HttpVerb;
use Sourcetoad\Logger\Models\AuditActivity;
Expand Down Expand Up @@ -181,11 +182,19 @@ public static function getNumericMorphMap(Model $model): int
$morphableTypeId = array_search($fcqn, $morphMap, true);
}

if (is_numeric($morphableTypeId)) {
return $morphableTypeId;
if (!is_numeric($morphableTypeId)) {
throw new InvalidArgumentException(
sprintf('%s has no numeric model map. Check `morphs` in Logger.', get_class($model)),
);
}

throw new \InvalidArgumentException(get_class($model) . " has no numeric model map. Check `morphs` in Logger.");
if ($morphableTypeId === 0) {
throw new InvalidArgumentException(
sprintf('0 is not a valid morph map key for %s. Check `morphs` in Logger.', get_class($model)),
);
}

return $morphableTypeId;
}

private function getHttpVerb(string $verb): int
Expand Down

0 comments on commit e990adb

Please sign in to comment.