Skip to content

Commit

Permalink
Merge branch 'main' into lance/pint-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lancepioch authored Oct 20, 2024
2 parents deb6603 + 020e41c commit 64943aa
Show file tree
Hide file tree
Showing 78 changed files with 274 additions and 190 deletions.
5 changes: 1 addition & 4 deletions app/Console/Commands/Egg/CheckEggUpdatesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ class CheckEggUpdatesCommand extends Command
{
protected $signature = 'p:egg:check-updates';

public function handle(): void
public function handle(EggExporterService $exporterService): void
{
/** @var EggExporterService $exporterService */
$exporterService = app(EggExporterService::class);

$eggs = Egg::all();
foreach ($eggs as $egg) {
try {
Expand Down
8 changes: 4 additions & 4 deletions app/Console/Commands/Environment/EmailSettingsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function handle(): void
/**
* Handle variables for SMTP driver.
*/
private function setupSmtpDriverVariables()
private function setupSmtpDriverVariables(): void
{
$this->variables['MAIL_HOST'] = $this->option('host') ?? $this->ask(
trans('command/messages.environment.mail.ask_smtp_host'),
Expand Down Expand Up @@ -101,7 +101,7 @@ private function setupSmtpDriverVariables()
/**
* Handle variables for mailgun driver.
*/
private function setupMailgunDriverVariables()
private function setupMailgunDriverVariables(): void
{
$this->variables['MAILGUN_DOMAIN'] = $this->option('host') ?? $this->ask(
trans('command/messages.environment.mail.ask_mailgun_domain'),
Expand All @@ -122,7 +122,7 @@ private function setupMailgunDriverVariables()
/**
* Handle variables for mandrill driver.
*/
private function setupMandrillDriverVariables()
private function setupMandrillDriverVariables(): void
{
$this->variables['MANDRILL_SECRET'] = $this->option('password') ?? $this->ask(
trans('command/messages.environment.mail.ask_mandrill_secret'),
Expand All @@ -133,7 +133,7 @@ private function setupMandrillDriverVariables()
/**
* Handle variables for postmark driver.
*/
private function setupPostmarkDriverVariables()
private function setupPostmarkDriverVariables(): void
{
$this->variables['MAIL_DRIVER'] = 'smtp';
$this->variables['MAIL_HOST'] = 'smtp.postmarkapp.com';
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/Schedule/ProcessRunnableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function handle(): int
* never throw an exception out, otherwise you'll end up killing the entire run group causing
* any other schedules to not process correctly.
*/
protected function processSchedule(Schedule $schedule)
protected function processSchedule(Schedule $schedule): void
{
if ($schedule->tasks->isEmpty()) {
return;
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/UpgradeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function handle(): void
$this->info(__('commands.upgrade.success'));
}

protected function withProgress(ProgressBar $bar, \Closure $callback)
protected function withProgress(ProgressBar $bar, \Closure $callback): void
{
$bar->clear();
$callback();
Expand Down
13 changes: 8 additions & 5 deletions app/Exceptions/DisplayException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Exception;
use Filament\Notifications\Notification;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Psr\Log\LoggerInterface;
use Illuminate\Http\Response;
Expand Down Expand Up @@ -49,7 +51,7 @@ public function getHeaders(): array
* and then redirecting them back to the page that they came from. If the
* request originated from an API hit, return the error in JSONAPI spec format.
*/
public function render(Request $request)
public function render(Request $request): bool|RedirectResponse|JsonResponse
{
if ($request->is('livewire/update')) {
Notification::make()
Expand All @@ -58,13 +60,14 @@ public function render(Request $request)
->danger()
->send();

return;
return false;
}

if ($request->expectsJson()) {
return response()->json(Handler::toArray($this), $this->getStatusCode(), $this->getHeaders());
}

// @phpstan-ignore-next-line
app(AlertsMessageBag::class)->danger($this->getMessage())->flash();

return redirect()->back()->withInput();
Expand All @@ -76,10 +79,10 @@ public function render(Request $request)
*
* @throws \Throwable
*/
public function report()
public function report(): void
{
if (!$this->getPrevious() instanceof \Exception || !Handler::isReportable($this->getPrevious())) {
return null;
return;
}

try {
Expand All @@ -88,6 +91,6 @@ public function report()
throw $this->getPrevious();
}

return $logger->{$this->getErrorLevel()}($this->getPrevious());
$logger->{$this->getErrorLevel()}($this->getPrevious());
}
}
1 change: 1 addition & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ protected function extractPrevious(\Throwable $e): array
*/
public static function toArray(\Throwable $e): array
{
// @phpstan-ignore-next-line
return (new self(app()))->convertExceptionToArray($e);
}
}
6 changes: 3 additions & 3 deletions app/Extensions/Themes/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

class Theme
{
public function js($path): string
public function js(string $path): string
{
return sprintf('<script src="%s"></script>' . PHP_EOL, $this->getUrl($path));
}

public function css($path): string
public function css(string $path): string
{
return sprintf('<link media="all" type="text/css" rel="stylesheet" href="%s"/>' . PHP_EOL, $this->getUrl($path));
}

protected function getUrl($path): string
protected function getUrl(string $path): string
{
return '/themes/panel/' . ltrim($path, '/');
}
Expand Down
18 changes: 11 additions & 7 deletions app/Filament/Pages/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ public function getTitle(): string

public string $activeTab = 'nodes';

public function getViewData(): array
private SoftwareVersionService $softwareVersionService;

public function mount(SoftwareVersionService $softwareVersionService): void
{
/** @var SoftwareVersionService $softwareVersionService */
$softwareVersionService = app(SoftwareVersionService::class);
$this->softwareVersionService = $softwareVersionService;
}

public function getViewData(): array
{
return [
'inDevelopment' => config('app.version') === 'canary',
'version' => $softwareVersionService->versionData()['version'],
'latestVersion' => $softwareVersionService->getPanel(),
'isLatest' => $softwareVersionService->isLatestPanel(),
'version' => $this->softwareVersionService->versionData()['version'],
'latestVersion' => $this->softwareVersionService->getPanel(),
'isLatest' => $this->softwareVersionService->isLatestPanel(),
'eggsCount' => Egg::query()->count(),
'nodesList' => ListNodes::getUrl(),
'nodesCount' => Node::query()->count(),
Expand Down Expand Up @@ -67,7 +71,7 @@ public function getViewData(): array
CreateAction::make()
->label(trans('dashboard/index.sections.intro-support.button_donate'))
->icon('tabler-cash')
->url($softwareVersionService->getDonations(), true)
->url($this->softwareVersionService->getDonations(), true)
->color('success'),
],
'helpActions' => [
Expand Down
15 changes: 8 additions & 7 deletions app/Filament/Pages/Installer/PanelInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Filament\Pages\Installer;

use App\Filament\Pages\Dashboard;
use App\Filament\Pages\Installer\Steps\AdminUserStep;
use App\Filament\Pages\Installer\Steps\CompletedStep;
use App\Filament\Pages\Installer\Steps\DatabaseStep;
Expand All @@ -13,7 +14,6 @@
use App\Traits\CheckMigrationsTrait;
use App\Traits\EnvironmentWriterTrait;
use Exception;
use Filament\Facades\Filament;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\Wizard;
use Filament\Forms\Concerns\InteractsWithForms;
Expand All @@ -24,6 +24,7 @@
use Filament\Pages\SimplePage;
use Filament\Support\Enums\MaxWidth;
use Filament\Support\Exceptions\Halt;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\HtmlString;
Expand All @@ -37,7 +38,7 @@ class PanelInstaller extends SimplePage implements HasForms
use EnvironmentWriterTrait;
use InteractsWithForms;

public $data = [];
public array $data = [];

protected static string $view = 'filament.pages.installer';

Expand All @@ -54,7 +55,7 @@ public static function isInstalled(): bool
return env('APP_INSTALLED', true);
}

public function mount()
public function mount(): void
{
abort_if(self::isInstalled(), 404);

Expand Down Expand Up @@ -93,7 +94,7 @@ protected function getFormStatePath(): ?string
return 'data';
}

public function submit()
public function submit(): RedirectResponse
{
// Disable installer
$this->writeToEnvironment(['APP_INSTALLED' => 'true']);
Expand All @@ -103,7 +104,7 @@ public function submit()
auth()->guard()->login($this->user, true);

// Redirect to admin panel
return redirect(Filament::getPanel('admin')->getUrl());
return redirect(Dashboard::getUrl());
}

public function writeToEnv(string $key): void
Expand Down Expand Up @@ -159,12 +160,12 @@ public function runMigrations(string $driver): void
}
}

public function createAdminUser(): void
public function createAdminUser(UserCreationService $userCreationService): void
{
try {
$userData = array_get($this->data, 'user');
$userData['root_admin'] = true;
$this->user = app(UserCreationService::class)->handle($userData);
$this->user = $userCreationService->handle($userData);
} catch (Exception $exception) {
report($exception);

Expand Down
3 changes: 2 additions & 1 deletion app/Filament/Pages/Installer/Steps/AdminUserStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Filament\Pages\Installer\Steps;

use App\Filament\Pages\Installer\PanelInstaller;
use App\Services\Users\UserCreationService;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Wizard\Step;

Expand All @@ -28,6 +29,6 @@ public static function make(PanelInstaller $installer): Step
->password()
->revealable(),
])
->afterValidation(fn () => $installer->createAdminUser());
->afterValidation(fn (UserCreationService $service) => $installer->createAdminUser($service));
}
}
2 changes: 1 addition & 1 deletion app/Filament/Pages/Installer/Steps/DatabaseStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static function make(PanelInstaller $installer): Step
});
}

private static function testConnection(string $driver, $host, $port, $database, $username, $password): bool
private static function testConnection(string $driver, string $host, string $port, string $database, string $username, string $password): bool
{
if ($driver === 'sqlite') {
return true;
Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Pages/Installer/Steps/RedisStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function make(PanelInstaller $installer): Step
});
}

private static function testConnection($host, $port, $username, $password): bool
private static function testConnection(string $host, string $port, string $username, string $password): bool
{
try {
config()->set('database.redis._panel_install_test', [
Expand Down
3 changes: 2 additions & 1 deletion app/Filament/Resources/ApiKeyResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Filament\Resources\ApiKeyResource\Pages;
use App\Models\ApiKey;
use Filament\Resources\Resource;
use Illuminate\Database\Eloquent\Model;

class ApiKeyResource extends Resource
{
Expand All @@ -21,7 +22,7 @@ public static function getNavigationBadge(): ?string
return static::getModel()::where('key_type', '2')->count() ?: null;
}

public static function canEdit($record): bool
public static function canEdit(Model $record): bool
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use App\Filament\Resources\DatabaseHostResource;
use App\Services\Databases\Hosts\HostCreationService;
use Closure;
use Exception;
use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
Expand All @@ -16,6 +18,8 @@

class CreateDatabaseHost extends CreateRecord
{
private HostCreationService $service;

protected static string $resource = DatabaseHostResource::class;

protected ?string $heading = 'Database Hosts';
Expand All @@ -24,6 +28,11 @@ class CreateDatabaseHost extends CreateRecord

protected ?string $subheading = '(database servers that can have individual databases)';

public function boot(HostCreationService $service): void
{
$this->service = $service;
}

public function form(Form $form): Form
{
return $form
Expand Down Expand Up @@ -94,10 +103,10 @@ protected function getFormActions(): array

protected function handleRecordCreation(array $data): Model
{
return resolve(HostCreationService::class)->handle($data);
return $this->service->handle($data);
}

public function exception($e, $stopPropagation): void
public function exception(Exception $e, Closure $stopPropagation): void
{
if ($e instanceof PDOException) {
Notification::make()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use App\Filament\Resources\DatabaseHostResource\RelationManagers\DatabasesRelationManager;
use App\Models\DatabaseHost;
use App\Services\Databases\Hosts\HostUpdateService;
use Closure;
use Exception;
use Filament\Actions;
use Filament\Forms;
use Filament\Forms\Components\Section;
Expand All @@ -21,6 +23,13 @@ class EditDatabaseHost extends EditRecord
{
protected static string $resource = DatabaseHostResource::class;

private HostUpdateService $hostUpdateService;

public function boot(HostUpdateService $hostUpdateService): void
{
$this->hostUpdateService = $hostUpdateService;
}

public function form(Form $form): Form
{
return $form
Expand Down Expand Up @@ -97,12 +106,16 @@ public function getRelationManagers(): array
];
}

protected function handleRecordUpdate($record, array $data): Model
protected function handleRecordUpdate(Model $record, array $data): Model
{
return resolve(HostUpdateService::class)->handle($record->id, $data);
if (!$record instanceof DatabaseHost) {
return $record;
}

return $this->hostUpdateService->handle($record, $data);
}

public function exception($e, $stopPropagation): void
public function exception(Exception $e, Closure $stopPropagation): void
{
if ($e instanceof PDOException) {
Notification::make()
Expand Down
Loading

0 comments on commit 64943aa

Please sign in to comment.