Skip to content

Commit

Permalink
♻️ deal with null and false returns (#995)
Browse files Browse the repository at this point in the history
* ♻️ deal with null and false returns

Co-authored-by: erikn69 <[email protected]>

* Fix

---------

Co-authored-by: erikn69 <[email protected]>
  • Loading branch information
willpower232 and erikn69 authored Jan 23, 2025
1 parent 2a5b584 commit f7cbe09
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 18 additions & 3 deletions src/Audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,13 @@ private function castDatetimeUTC($model, $value)
}

if (preg_match('/^(\d{4})-(\d{1,2})-(\d{1,2})$/', $value)) {
return Date::instance(Carbon::createFromFormat('Y-m-d', $value, Date::now('UTC')->getTimezone())->startOfDay());
$date = Carbon::createFromFormat('Y-m-d', $value, Date::now('UTC')->getTimezone());

if (! $date) {
return $value;
}

return Date::instance($date->startOfDay());
}

if (preg_match('/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/', $value)) {
Expand Down Expand Up @@ -259,7 +265,11 @@ public function getMetadata(bool $json = false, int $options = 0, int $depth = 5
}
}

return $json ? json_encode($metadata, $options, $depth) : $metadata;
if (! $json) {
return $metadata;
}

return json_encode($metadata, $options, $depth) ?: '{}';
}

/**
Expand All @@ -285,7 +295,12 @@ public function getModified(bool $json = false, int $options = 0, int $depth = 5
}
}

return $json ? json_encode($modified, $options, $depth) : $modified;

if (! $json) {
return $modified;
}

return json_encode($modified, $options, $depth) ?: '{}';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function registerAuditingServiceProvider()

$appConfig = file_get_contents(config_path('app.php'));

if (Str::contains($appConfig, 'OwenIt\\Auditing\\AuditingServiceProvider::class')) {
if (! $appConfig || Str::contains($appConfig, 'OwenIt\\Auditing\\AuditingServiceProvider::class')) {
return;
}

Expand Down

0 comments on commit f7cbe09

Please sign in to comment.