Skip to content

Commit

Permalink
♻️ deal with null and false returns
Browse files Browse the repository at this point in the history
Co-authored-by: erikn69 <erikn_69@hotmail.com>
  • Loading branch information
willpower232 and erikn69 committed Jan 18, 2025
1 parent 559b391 commit 475a41d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
28 changes: 25 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 === null) {
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,15 @@ public function getMetadata(bool $json = false, int $options = 0, int $depth = 5
}
}

return $json ? json_encode($metadata, $options, $depth) : $metadata;
if ($json === true) {
$metadata = json_encode($metadata, $options, $depth);

if ($metadata === false) {
return [];
}
}

return $metadata;
}

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

return $json ? json_encode($modified, $options, $depth) : $modified;
if ($json === true) {
$modified = json_encode($modified, $options, $depth);

if ($modified === false) {
return [];
}
}

return $modified;
}

/**
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 === false || Str::contains($appConfig, 'OwenIt\\Auditing\\AuditingServiceProvider::class')) {
return;
}

Expand Down

0 comments on commit 475a41d

Please sign in to comment.