Skip to content

Commit

Permalink
adjust prs
Browse files Browse the repository at this point in the history
  • Loading branch information
bezhanSalleh committed Jan 24, 2024
1 parent 91f3b23 commit 524de3d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 38 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"require-dev": {
"laravel/pint": "^1.0",
"nunomaduro/collision": "^7.0",
"nunomaduro/larastan": "^2.0",
"larastan/larastan": "^2.0",
"orchestra/testbench": "^8.0",
"pestphp/pest": "^2.9",
"phpunit/phpunit": "^10.0",
Expand Down
6 changes: 6 additions & 0 deletions src/Facades/FilamentExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
use Illuminate\Support\Facades\Facade;

/**
* @method static void report(\Throwable $exception)
* @method static string getModel()
* @method static void reportException(\Throwable $exception)
* @method static array stringify(void $data)
* @method static bool store(array $data)
*
* @see \BezhanSalleh\FilamentExceptions\FilamentExceptions
*/
class FilamentExceptions extends Facade
Expand Down
46 changes: 11 additions & 35 deletions src/FilamentExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace BezhanSalleh\FilamentExceptions;

use BezhanSalleh\FilamentExceptions\Models\Exception as ExceptionModel;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Foundation\Application;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
Expand All @@ -11,44 +12,30 @@

class FilamentExceptions
{
/**
* @var Request
*/
protected $request;

protected Application $app;

/**
* Reporter constructor.
*/
public function __construct(Request $request)
{
$this->request = $request;
public function __construct(
protected Request $request
) {
}

/**
* @return void
* @throws BindingResolutionException
*/
public static function report(Throwable $exception)
public static function report(Throwable $exception): void
{
$reporter = new static(request());

$reporter->reportException($exception);
}

public static function model(): string
public static function getModel(): string
{
if (config('filament-exceptions.exception_model') === null) {
return ExceptionModel::class;
}

return config('filament-exceptions.exception_model');
return config('filament-exceptions.exception_model') ?? ExceptionModel::class;
}

/**
* @return void
* @throws BindingResolutionException
*/
public function reportException(Throwable $exception)
public function reportException(Throwable $exception): void
{
$data = [
'method' => request()->getMethod(),
Expand All @@ -69,31 +56,20 @@ public function reportException(Throwable $exception)

$data = $this->stringify($data);

try {
$this->store($data);
} catch (Throwable $e) {
throw $e;
}
$this->store($data);
}

/**
* Convert all items to string.
*/
public function stringify($data): array
{
return array_map(function ($item) {
return is_array($item) ? json_encode($item, JSON_OBJECT_AS_ARRAY) : (string) $item;
}, $data);
}

/**
* Store exception info to db.
*/
public function store(array $data): bool
{
try {
$this->model()::query()->create($data);

return true;
} catch (Throwable $e) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/ExceptionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ExceptionResource extends Resource
{
public static function getModel(): string
{
return FilamentExceptions::model();
return FilamentExceptions::getModel();
}

public static function getModelLabel(): string
Expand Down Expand Up @@ -50,7 +50,7 @@ public static function getSlug(): string
public static function getNavigationBadge(): ?string
{
if (config('filament-exceptions.navigation_badge')) {
return static::getModel()::count();
return static::getEloquentQuery()->count();
}

return null;
Expand Down

0 comments on commit 524de3d

Please sign in to comment.