Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update phpstan to latest #804

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a9852e5
Fix these
lancepioch Dec 9, 2024
d9386fd
Update phpstan
lancepioch Dec 9, 2024
3811156
Transform these into their identifiers instead
lancepioch Dec 9, 2024
1515116
Fix custom rule
lancepioch Dec 9, 2024
23148da
License is wrong
lancepioch Dec 9, 2024
6adf8e1
Update these
lancepioch Dec 9, 2024
a1a9b12
Pint fixes
lancepioch Dec 9, 2024
9d672bd
Fix this
lancepioch Dec 9, 2024
c1e4eed
Consolidate these
lancepioch Dec 9, 2024
6f82c30
Never supported PHP 7
lancepioch Jan 3, 2025
3ba9d1b
Better evaluation
lancepioch Jan 3, 2025
9725d6f
Fixes
lancepioch Jan 3, 2025
8663cb8
Don’t need ignore
lancepioch Jan 3, 2025
ce99d26
Replace trait with service
lancepioch Jan 3, 2025
ce3e1e3
Subusers are simply the many to many relationship between Servers and…
lancepioch Jan 3, 2025
73802e8
Adjust to remove ignores
lancepioch Jan 3, 2025
19cee9e
Use new query builder instead!
lancepioch Jan 3, 2025
2d8f9c5
wip
lancepioch Jan 3, 2025
6d64de2
Merge branch 'main' into lance/rules
lancepioch Jan 3, 2025
7047d29
Update composer
lancepioch Jan 3, 2025
a42887f
Quick fixes
lancepioch Jan 3, 2025
3bd977b
Use realtime facade
lancepioch Jan 3, 2025
266308b
Small fixes
lancepioch Jan 3, 2025
cef29fe
Convert to static to avoid new
lancepioch Jan 3, 2025
62429c1
Update to statics
lancepioch Jan 3, 2025
0a49924
Don’t modify protected properties directly
lancepioch Jan 3, 2025
14eb64f
Run pint
lancepioch Jan 3, 2025
dd9d0d6
Change to correct method
lancepioch Jan 4, 2025
86d3f2d
Give up and use the facade
lancepioch Jan 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions .github/docker/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,6 @@
# /etc/nginx/conf.d/
#

# The MIT License (MIT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file isn't used anymore anyways, is it? The docker image now uses caddy?

#
# Pterodactyl®
# Copyright © Dane Everitt <dane@daneeveritt.com> and contributors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

server {
listen 80;
server_name _;
Expand Down
14 changes: 6 additions & 8 deletions app/Console/Commands/Schedule/ProcessRunnableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
use App\Models\Schedule;
use Illuminate\Database\Eloquent\Builder;
use App\Services\Schedules\ProcessScheduleService;
use Throwable;

class ProcessRunnableCommand extends Command
{
protected $signature = 'p:schedule:process';

protected $description = 'Process schedules in the database and determine which are ready to run.';

/**
* Handle command execution.
*/
public function handle(): int
public function handle(ProcessScheduleService $processScheduleService): int
{
$schedules = Schedule::query()
->with('tasks')
Expand All @@ -35,7 +33,7 @@ public function handle(): int
$bar = $this->output->createProgressBar(count($schedules));
foreach ($schedules as $schedule) {
$bar->clear();
$this->processSchedule($schedule);
$this->processSchedule($processScheduleService, $schedule);
$bar->advance();
$bar->display();
}
Expand All @@ -50,20 +48,20 @@ 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): void
protected function processSchedule(ProcessScheduleService $processScheduleService, Schedule $schedule): void
{
if ($schedule->tasks->isEmpty()) {
return;
}

try {
$this->getLaravel()->make(ProcessScheduleService::class)->handle($schedule);
$processScheduleService->handle($schedule);

$this->line(trans('command/messages.schedule.output_line', [
'schedule' => $schedule->name,
'id' => $schedule->id,
]));
} catch (\Throwable|\Exception $exception) {
} catch (Throwable $exception) {
logger()->error($exception, ['schedule_id' => $schedule->id]);

$this->error(__('commands.schedule.process.no_tasks') . " #$schedule->id: " . $exception->getMessage());
Expand Down
28 changes: 10 additions & 18 deletions app/Console/Commands/Server/BulkPowerActionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,13 @@ class BulkPowerActionCommand extends Command

protected $description = 'Perform bulk power management on large groupings of servers or nodes at once.';

/**
* BulkPowerActionCommand constructor.
*/
public function __construct(private DaemonPowerRepository $powerRepository, private ValidatorFactory $validator)
{
parent::__construct();
}

/**
* Handle the bulk power request.
*
* @throws \Illuminate\Validation\ValidationException
*/
public function handle(): void
public function handle(DaemonPowerRepository $powerRepository, ValidatorFactory $validator): void
{
$action = $this->argument('action');
$nodes = empty($this->option('nodes')) ? [] : explode(',', $this->option('nodes'));
$servers = empty($this->option('servers')) ? [] : explode(',', $this->option('servers'));

$validator = $this->validator->make([
$validator = $validator->make([
'action' => $action,
'nodes' => $nodes,
'servers' => $servers,
Expand All @@ -64,11 +51,14 @@ public function handle(): void
}

$bar = $this->output->createProgressBar($count);
$powerRepository = $this->powerRepository;
// @phpstan-ignore-next-line
$this->getQueryBuilder($servers, $nodes)->each(function (Server $server) use ($action, $powerRepository, &$bar) {

$this->getQueryBuilder($servers, $nodes)->get()->each(function ($server, int $index) use ($action, $powerRepository, &$bar): mixed {
$bar->clear();

if (!$server instanceof Server) {
return null;
}

try {
$powerRepository->setServer($server)->send($action);
} catch (DaemonConnectionException $exception) {
Expand All @@ -82,6 +72,8 @@ public function handle(): void

$bar->advance();
$bar->display();

return null;
});

$this->line('');
Expand Down
4 changes: 0 additions & 4 deletions app/Console/Commands/UpgradeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ public function handle(): void
$this->line($this->getUrl());
}

if (version_compare(PHP_VERSION, '7.4.0') < 0) {
$this->error(__('commands.upgrade.php_version') . ' [' . PHP_VERSION . '].');
}

$user = 'www-data';
$group = 'www-data';
if ($this->input->isInteractive()) {
Expand Down
24 changes: 24 additions & 0 deletions app/Eloquent/BackupQueryBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Eloquent;

use Illuminate\Database\Eloquent\Builder;

/**
* @template TModel of \Illuminate\Database\Eloquent\Model
*
* @extends Builder<TModel>
*/
class BackupQueryBuilder extends Builder
{
public function nonFailed(): self
{
$this->where(function (Builder $query) {
$query
->whereNull('completed_at')
->orWhere('is_successful', true);
});

return $this;
}
}
2 changes: 1 addition & 1 deletion app/Enums/EditorLanguages.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ enum EditorLanguages: string implements HasLabel
case yaml = 'yaml';
case json = 'json';

public function getLabel(): ?string
public function getLabel(): string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be reverted? The HasLabel interface expects ?string.

{
return $this->name;
}
Expand Down
26 changes: 14 additions & 12 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Symfony\Component\Mailer\Exception\TransportException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Throwable;

class Handler extends ExceptionHandler
{
Expand Down Expand Up @@ -179,10 +180,7 @@ public function invalidJson($request, ValidationException $exception): JsonRespo
return response()->json(['errors' => $errors], $exception->status);
}

/**
* Return the exception as a JSONAPI representation for use on API requests.
*/
protected function convertExceptionToArray(\Throwable $e, array $override = []): array
public static function exceptionToArray(Throwable $e, array $override = []): array
{
$match = self::$exceptionResponseCodes[get_class($e)] ?? null;

Expand Down Expand Up @@ -214,7 +212,7 @@ protected function convertExceptionToArray(\Throwable $e, array $override = []):
'trace' => Collection::make($e->getTrace())
->map(fn ($trace) => Arr::except($trace, ['args']))
->all(),
'previous' => Collection::make($this->extractPrevious($e))
'previous' => Collection::make(self::extractPrevious($e))
->map(fn ($exception) => $exception->getTrace())
->map(fn ($trace) => Arr::except($trace, ['args']))
->all(),
Expand All @@ -225,6 +223,14 @@ protected function convertExceptionToArray(\Throwable $e, array $override = []):
return ['errors' => [array_merge($error, $override)]];
}

/**
* Return the exception as a JSONAPI representation for use on API requests.
*/
protected function convertExceptionToArray(Throwable $e, array $override = []): array
{
return self::exceptionToArray($e, $override);
}

/**
* Return an array of exceptions that should not be reported.
*/
Expand All @@ -251,15 +257,12 @@ protected function unauthenticated($request, AuthenticationException $exception)
* Extracts all the previous exceptions that lead to the one passed into this
* function being thrown.
*
* @return \Throwable[]
* @return Throwable[]
*/
protected function extractPrevious(\Throwable $e): array
public static function extractPrevious(Throwable $e): array
{
$previous = [];
while ($value = $e->getPrevious()) {
if (!$value instanceof \Throwable) {
break;
}
$previous[] = $value;
$e = $value;
}
Expand All @@ -273,7 +276,6 @@ protected function extractPrevious(\Throwable $e): array
*/
public static function toArray(\Throwable $e): array
{
// @phpstan-ignore-next-line
return (new self(app()))->convertExceptionToArray($e);
return self::exceptionToArray($e);
}
}
23 changes: 0 additions & 23 deletions app/Extensions/Filesystem/S3Filesystem.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
<?php

/* The MIT License (MIT)

Pterodactyl®
Copyright © Dane Everitt <dane@daneeveritt.com> and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. */

namespace App\Extensions\Filesystem;

use Aws\S3\S3ClientInterface;
Expand Down
24 changes: 11 additions & 13 deletions app/Filament/Admin/Pages/Health.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Filament\Pages\Page;
use Illuminate\Support\Facades\Artisan;
use Spatie\Health\Commands\RunHealthChecksCommand;
use Spatie\Health\ResultStores\ResultStore;
use Facades\Spatie\Health\ResultStores\ResultStore;

class Health extends Page
{
Expand All @@ -18,10 +18,12 @@ class Health extends Page

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

// @phpstan-ignore-next-line
protected $listeners = [
'refresh-component' => '$refresh',
];
protected function getListeners(): array
{
return [
'refresh-component' => '$refresh',
];
}

protected function getActions(): array
{
Expand All @@ -34,8 +36,7 @@ protected function getActions(): array

protected function getViewData(): array
{
// @phpstan-ignore-next-line
$checkResults = app(ResultStore::class)->latestResults();
$checkResults = ResultStore::latestResults();

if ($checkResults === null) {
Artisan::call(RunHealthChecksCommand::class);
Expand Down Expand Up @@ -63,8 +64,7 @@ public function refresh(): void

public static function getNavigationBadge(): ?string
{
// @phpstan-ignore-next-line
$results = app(ResultStore::class)->latestResults();
$results = ResultStore::latestResults();

if ($results === null) {
return null;
Expand All @@ -86,8 +86,7 @@ public static function getNavigationBadgeColor(): string

public static function getNavigationBadgeTooltip(): ?string
{
// @phpstan-ignore-next-line
$results = app(ResultStore::class)->latestResults();
$results = ResultStore::latestResults();

if ($results === null) {
return null;
Expand All @@ -108,8 +107,7 @@ public static function getNavigationBadgeTooltip(): ?string

public static function getNavigationIcon(): string
{
// @phpstan-ignore-next-line
$results = app(ResultStore::class)->latestResults();
$results = ResultStore::latestResults();

if ($results === null) {
return 'tabler-heart-question';
Expand Down
3 changes: 2 additions & 1 deletion app/Filament/Admin/Resources/UserResource/Pages/EditUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Filament\Admin\Resources\UserResource;
use App\Models\Role;
use App\Models\User;
use App\Services\Helpers\LanguageService;
use Filament\Actions\DeleteAction;
use Filament\Forms\Components\CheckboxList;
use Filament\Forms\Components\Hidden;
Expand Down Expand Up @@ -40,7 +41,7 @@ public function form(Form $form): Form
->required()
->hidden()
->default('en')
->options(fn (User $user) => $user->getAvailableLanguages()),
->options(fn (LanguageService $languageService) => $languageService->getAvailableLanguages()),
Hidden::make('skipValidation')
->default(true),
CheckboxList::make('roles')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Filament\Tables\Columns\SelectColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Collection;

class ServersRelationManager extends RelationManager
{
Expand All @@ -33,7 +34,9 @@ public function table(Table $table): Table
->label('Suspend All Servers')
->color('warning')
->action(function (SuspensionService $suspensionService) use ($user) {
foreach ($user->servers()->whereNot('status', ServerState::Suspended)->get() as $server) {
/** @var Collection<Server> $servers */
$servers = $user->servers()->whereNot('status', ServerState::Suspended)->get();
foreach ($servers as $server) {
$suspensionService->toggle($server);
}
}),
Expand All @@ -42,7 +45,9 @@ public function table(Table $table): Table
->label('Unsuspend All Servers')
->color('primary')
->action(function (SuspensionService $suspensionService) use ($user) {
foreach ($user->servers()->where('status', ServerState::Suspended)->get() as $server) {
/** @var Collection<Server> $servers */
$servers = $user->servers()->where('status', ServerState::Suspended)->get();
foreach ($servers as $server) {
$suspensionService->toggle($server, SuspensionService::ACTION_UNSUSPEND);
}
}),
Expand Down
Loading
Loading